You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: snapshot.rs
    path of file: ./repos/spatialos-sdk-rs/spatialos-sdk/src
    
    the code of the file until where you have to start completion: use crate::{entity::Entity, utils::cstr_to_string, EntityId};
use spatialos_sdk_sys::worker::*;
use std::{ffi::CString, path::Path};

#[derive(Debug)]
pub enum SnapshotError {
    BadState(String),
    InvalidData(String),
    EntitySerializationFailure(String),
    EOF,
}

impl From<Worker_SnapshotState> for SnapshotError {
    fn from(state: Worker_SnapshotState) -> SnapshotError {
        match Worker_StreamState::from(state.stream_state) {
            Worker_StreamState_WORKER_STREAM_STATE_BAD => {
                SnapshotError::BadState(cstr_to_string(state.error_message))
            }
            Worker_StreamState_WORKER_STREAM_STATE_INVALID_DATA => {
                SnapshotError::InvalidData(cstr_to_string(state.error_message))
            }
            Worker_StreamState
    
    pub fn new<P: AsRef<Path>>(filename: P) -> Result<Self, SnapshotError> {
        let filename_cstr = CString::new(filename.as_ref().to_str().unwrap()).unwrap();

        let default_vtable = Default::default();
        let stream_ptr = unsafe {
            Worker_SnapshotInputStream_Create(
                filename_cstr.as_ptr(),
                &Worker_SnapshotParameters {
                    default_component_vtable: &default_vtable,
                    ..Default::default()
                },
            )
        };

        let state = unsafe { Worker_SnapshotInputStream_GetState(stream_ptr) };
        match Worker_StreamState::from(state.stream_state) {
            Worker_StreamState_WORKER_STREAM_STATE_GOOD => {
                Ok(SnapshotInputStream { ptr: stream_ptr })
            }
            _ => {
                unsafe { Worker_SnapshotInputStream_Destroy(stream_ptr) };
                Err(SnapshotError::from(state))
            }
        }
    }