Skip to main content

save_state

Function save_state 

Source
pub fn save_state<T: Serialize>(path: &Path, state: &T) -> Result<()>
Expand description

Save state to a JSON file atomically.

Writes to a temporary file in the same directory, then renames it into place. This guarantees that the state file is always either the old version or the new version, never a partially-written mix.

Parent directories are created automatically if they don’t exist.

§Errors

Returns io::Error if serialization, directory creation, writing, or renaming fails.