fn save<S, Ser>(state: &S) -> Result<Token<S, Ser>>
where
    S: State<Ser>,
    Ser: Serialization,
{
    let state = state
        .to_json()
        .with_context(|| format!("while serializing {:?}", state))?;
    let sha: [u8; 32] = Sha256::digest(&state).into();
    let token = Token::new(sha);
    let p = token.path();
    std::fs::write(&p, &state).with_context(|| format!("while serializing to {}", p.display()))?;
    Ok(token)
}
/// Persist a new version of a state type, getting back a unique key to later
/// load it with.
Persist a new version of a state type, getting back a unique key to later
load it with.
Persist a new version of a state type getting back a unique key to later load it with .
fn save<S, Ser>(state: &S) -> Result<Token<S, Ser>>
where
    S: State<Ser>,
    Ser: Serialization,
{
    let state = state
        .to_json()
        .with_context(|| format!("while serializing {:?}", state))?;
    let sha: [u8; 32] = Sha256::digest(&state).into();
    let token = Token::new(sha);
    let p = token.path();
    std::fs::write(&p, &state).with_context(|| format!("while serializing to {}", p.display()))?;
    Ok(token)
}
fn save < S , Ser > ( state : & S ) -> Result < Token < S , Ser > > where S : State < Ser > , Ser : Serialization , { let state = state . to_json ( ) . with_context ( | | format ! ( " " state ) ) ? ; let sha : [ u8 ; 32 ] = Sha256 :: digest ( & state ) . into ( ) ; let token = Token :: new ( sha ) ; let p = token . path ( ) ; std :: fs :: write ( & p , & state ) . with_context ( | | format ! ( " " p display ( ) ) ) ? ; Ok ( token ) }
Persist a new version of a state type, getting back a unique key to later
load it with.
Persist a new version of a state type getting back a unique key to later load it with .
state
&S
state
&S