snaplog

Crates.iosnaplog
lib.rssnaplog
version0.4.0
sourcesrc
created_at2022-07-10 14:57:37.043802
updated_at2022-09-25 11:35:31.63057
descriptionA library for easily recording changes to values
homepage
repositoryhttps://github.com/epbuennig/snaplog/
max_upload_size
id623160
size76,981
Erik Bünnig (epbuennig)

documentation

README

Snaplog

Snaplog is a library that provides the Snaplog type, a struct that records changes to a value of type T.

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_change(|_| "/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);

Links

Commit count: 34

cargo fmt