pub fn load_state<P>(path: P) -> Result<State, Error>
    where
        P: AsRef<Path>,
    {
        let mut lst = State {
            consensus_state: consensus::State::default(),
            state_file_path: path.as_ref().to_owned(),
        };

        match fs::read_to_string(path.as_ref()) {
            Ok(contents) => {
                lst.consensus_state = serde_json::from_str(&contents).map_err(|e| {
                    err!(
                        ParseError,
                        "error parsing {}: {}",
                        path.as_ref().display(),
                        e
                    )
                })?;
                Ok(lst)
            }
            Err(e) => {
                if e.kind() == io::ErrorKind::NotFound {
                    lst.sync_to_disk()?;
                    Ok(lst)
                } else {
                    Err(e.into())
                }
            }
        }
    }
/// Load the state from the given path
Load the state from the given path
Load the state from the given path
pub fn load_state<P>(path: P) -> Result<State, Error>
    where
        P: AsRef<Path>,
    {
        let mut lst = State {
            consensus_state: consensus::State::default(),
            state_file_path: path.as_ref().to_owned(),
        };
        match fs::read_to_string(path.as_ref()) {
            Ok(contents) => {
                lst.consensus_state = serde_json::from_str(&contents).map_err(|e| {
                    err!(
                        ParseError,
                        "error parsing {}: {}",
                        path.as_ref().display(),
                        e
                    )
                })?;
                Ok(lst)
            }
            Err(e) => {
                if e.kind() == io::ErrorKind::NotFound {
                    lst.sync_to_disk()?;
                    Ok(lst)
                } else {
                    Err(e.into())
                }
            }
        }
    }
pub fn load_state < P > ( path : P ) -> Result < State , Error > where P : AsRef < Path > , { let mut lst = State { consensus_state : consensus :: State :: default ( ) , state_file_path : path . as_ref ( ) . to_owned ( ) , } ; match fs :: read_to_string ( path . as_ref ( ) ) { Ok ( contents ) => { lst . consensus_state = serde_json :: from_str ( & contents ) . map_err ( | e | { err ! ( ParseError " " path as_ref ( ) display ( ) e ) } ) ? ; Ok ( lst ) } Err ( e ) => { if e . kind ( ) == io :: ErrorKind :: NotFound { lst . sync_to_disk ( ) ? ; Ok ( lst ) } else { Err ( e . into ( ) ) } } } }
Load the state from the given path
Load the state from the given path
path
P