#snapshot #change #changelog

snaplog

A library for easily recording changes to values

7 unstable releases (3 breaking)

0.4.0 Sep 25, 2022
0.3.2 Sep 11, 2022
0.3.1 Jul 16, 2022
0.2.1 Jul 14, 2022
0.1.0 Jul 10, 2022

#1267 in Algorithms

MIT license

74KB
716 lines

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


lib.rs:

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);

No runtime deps