forgetful 0.1.0

Track and forget values within a specific scope, enabling detection of repeated values.
Documentation
  • Coverage
  • 16.67%
    1 out of 6 items documented1 out of 4 items with examples
  • Size
  • Source code size: 8.34 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.69 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • cwaldren/forgetful-observer
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • cwaldren

forgetful observer

This crate allows you to track items seen during execution of an algorithm using RAII.

An observation of a particular item is represented by an Obervation<T>. When this object falls out of scope, the item is forgotten.

This might be useful when implementing a recursive algorithm on a graph that must detect cycles.

Here's an example:

let observer = Observer::new();
{
    let observation = observer.notice("foo").expect("never seen before");
    // While 'observation' is in scope, subsequent calls to notice return None.
    assert!(observer.notice("foo").is_none());
}
// Now that 'observation' is out of scope, this will return Some(Observation).
assert!(observer.notice("foo").is_some());

The Observer can track any item that is Eq + Hash. For example:

observer.notice(&42);

Internally, Observer stores references to the items it notices in a HashSet.

Upon the Observation's destruction, the item reference is removed from the set.