pub fn load<P: AsRef<Path> + Debug>(snapshot_file: P) -> AppResult<Snapshot> {
        // open file, and create a new one if not found
        let json_file = match File::open(&snapshot_file) {
            Ok(file) => file,
            Err(e) => {
                if e.kind() == ErrorKind::NotFound {
                    return Ok(Snapshot::default());
                } else {
                    return Err(AppError::from_error(
                        e,
                        &format!("error loading snapshot file: {:?}", snapshot_file),
                    ));
                }
            }
        };

        let reader = BufReader::new(json_file);

        // deserialize JSON
        let snapshot: Snapshot = serde_json::from_reader(reader)
            .map_err(|e| context!(e, "unable load snapshot file: {:?}", snapshot_file))?;
        Ok(snapshot)
    }
/// Deserialize a snapshot from a JSON file.
Deserialize a snapshot from a JSON file.
Deserialize a snapshot from a JSON file .
pub fn load<P: AsRef<Path> + Debug>(snapshot_file: P) -> AppResult<Snapshot> {
        // open file, and create a new one if not found
        let json_file = match File::open(&snapshot_file) {
            Ok(file) => file,
            Err(e) => {
                if e.kind() == ErrorKind::NotFound {
                    return Ok(Snapshot::default());
                } else {
                    return Err(AppError::from_error(
                        e,
                        &format!("error loading snapshot file: {:?}", snapshot_file),
                    ));
                }
            }
        };
        let reader = BufReader::new(json_file);
        // deserialize JSON
        let snapshot: Snapshot = serde_json::from_reader(reader)
            .map_err(|e| context!(e, "unable load snapshot file: {:?}", snapshot_file))?;
        Ok(snapshot)
    }
pub fn load < P : AsRef < Path > + Debug > ( snapshot_file : P ) -> AppResult < Snapshot > { // open file, and create a new one if not found let json_file = match File :: open ( & snapshot_file ) { Ok ( file ) => file , Err ( e ) => { if e . kind ( ) == ErrorKind :: NotFound { return Ok ( Snapshot :: default ( ) ) ; } else { return Err ( AppError :: from_error ( e , & format ! ( " " snapshot_file ) , ) ) ; } } } ; let reader = BufReader :: new ( json_file ) ; // deserialize JSON let snapshot : Snapshot = serde_json :: from_reader ( reader ) . map_err ( | e | context ! ( e " " snapshot_file ) ) ? ; Ok ( snapshot ) }
Deserialize a snapshot from a JSON file.
Deserialize a snapshot from a JSON file .
snapshot_file
P
snapshot_file
P