4 releases (2 breaking)

Uses old Rust 2015

0.4.0 Dec 6, 2019
0.3.0 Nov 19, 2019
0.2.0 Jan 27, 2019
0.1.1 Jun 29, 2018
0.1.0 Jun 29, 2018
Download history 1860/week @ 2022-03-05 2175/week @ 2022-03-12 1756/week @ 2022-03-19 1756/week @ 2022-03-26 2119/week @ 2022-04-02 1781/week @ 2022-04-09 1826/week @ 2022-04-16 1916/week @ 2022-04-23 2113/week @ 2022-04-30 1944/week @ 2022-05-07 2290/week @ 2022-05-14 2317/week @ 2022-05-21 1856/week @ 2022-05-28 1778/week @ 2022-06-04 2212/week @ 2022-06-11 2109/week @ 2022-06-18

8,258 downloads per month
Used in 50 crates (2 directly)

MIT license

17KB
338 lines

Census

Build status

This crate makes it possible to create an inventory object that keeps track of instances of a given type.

It is used in tantivy to get an accurate list of all of the files that are still in use by the index, and avoid garbage collecting them.

This TrackedObject<T> instance include some reference counting logic to ensure that the object is removed from the inventory once the last instance is dropped.

Example


extern crate census;

use census::{Inventory, TrackedObject};

fn main() {
    let inventory = Inventory::new();

    //  Each object tracked needs to be registered explicitely in the Inventory.
    //  A `TrackedObject<T>` wrapper is then returned.
    let one = inventory.track("one".to_string());
    let two = inventory.track("two".to_string());

    // A snapshot  of the list of living instances can be obtained...
    // (no guarantee on their order)
    let living_instances: Vec<TrackedObject<String>> = inventory.list();
    assert_eq!(living_instances.len(), 2);
}

No runtime deps