versioned
This tiny crate provides just the pointer-like Versioned<T> wrapper,
which counts the number of times its contained T value has been mutably accessed.
This may be useful when caching certain calculation results based on objects, which are expensive to compare or hash, such as large collections. In such cases it might be more convenient to store object version and later check if it changed.
use Versioned;
let mut versioned_value = new;
assert_eq!;
// This is an immutable dereference, so it won't change the version.
let value_len = versioned_value.len;
assert_eq!;
// Now we mutate the value twice.
versioned_value.push_str;
versioned_value.push_str;
assert_eq!;
assert_eq!;
Versioned<T> implements Deref,
AsRef and their Mut counterparts.
In particular, due to Deref coercion,
Versioned<T> values can be passed as &T and &mut T
parameters to functions:
use Versioned;
let mut versioned_value = new;
look_at;
assert_eq!;
modify;
assert_eq!;
Note from the example above that, since mutations are counted based on mutable dereferences,
version got increased on mutable dereference in the call to modify(), even though
ultimately no mutation of the value itself took place.