/// Load a specific version of a state type, using the key returned by [save]
Load a specific version of a state type, using the key returned by [save]
Load a specific version of a state type using the key returned by [ save ]
fn load<S, Ser>(token: Token<S, Ser>) -> Result<Option<S>>
where
    S: State<Ser>,
    Ser: Serialization,
{
    match std::fs::read(token.path()) {
        Err(e) => {
            match e.kind() {
                std::io::ErrorKind::NotFound => Ok(None),
                _ => Err(anyhow::Error::from(e)
                    .context(format!("while opening {}", token.path().display()))),
            }
        }
        Ok(bytes) => S::from_json(bytes)
            .map(Some)
            .with_context(|| format!("while deserializing {}", token.path().display())),
    }
}
fn load < S , Ser > ( token : Token < S , Ser > ) -> Result < Option < S > > where S : State < Ser > , Ser : Serialization , { match std :: fs :: read ( token . path ( ) ) { Err ( e ) => { match e . kind ( ) { std :: io :: ErrorKind :: NotFound => Ok ( None ) , _ => Err ( anyhow :: Error :: from ( e ) . context ( format ! ( " " token path ( ) display ( ) ) ) ) , } } Ok ( bytes ) => S :: from_json ( bytes ) . map ( Some ) . with_context ( | | format ! ( " " token path ( ) display ( ) ) ) , } }
Load a specific version of a state type, using the key returned by [save]
Load a specific version of a state type using the key returned by [ save ]
token
Token<S, Ser>