Crate snaplog

Crate snaplog 

Source
Expand description

Snaplog is a library that provides the Snaplog type, a struct that records changes to a value of type T by saving a snapshot of the value after each change.

§Examples

use snaplog::{Select, Snaplog};
let mut snaplog: Snaplog<_> = vec![
    "/path/to/file".to_string(),
    "/path/to/file-backup".to_string(),
    "/path/file-backup".to_string()
].try_into()?;

assert_eq!(snaplog.has_changes(), true);

snaplog.record_change(|prev| format!("{prev}-copy"));
snaplog.record("/path/file".to_string());

assert_eq!(snaplog[Select::Initial], "/path/to/file");
assert_eq!(snaplog[Select::At(3)],   "/path/file-backup-copy");
assert_eq!(snaplog[Select::Current], "/path/file");

snaplog.clear_history();

assert_eq!(snaplog.history(), ["/path/file"]);
assert_eq!(snaplog.has_changes(), false);

Re-exports§

pub use full::Snaplog;
pub use scoped::AsThinScoped;
pub use scoped::AsThinScopedMut;
pub use scoped::IntoScoped;
pub use scoped::Snaplog as ScopedSnaplog;

Modules§

full
A full Snaplog and it’s associated types. A Snaplog is used to record snapshots of changes to a value, such as successive edits to a file’s contents.
scoped
A scoped ScopedSnaplog and it’s associated types. A ScopedSnaplog is used to record snapshots of changes to only part of a value, such as successive edits to a file’s name without editing it’s ancestors.

Structs§

EmptyHistoryError
An Error that occurs when trying to create a Snaplog from an empty Vec.

Enums§

Select
Select a snapshot in a snaplog.