6 releases

Uses old Rust 2015

0.4.2 Jan 26, 2024
0.4.1 Sep 8, 2022
0.4.0 Dec 6, 2019
0.3.0 Nov 19, 2019
0.1.1 Jun 29, 2018

#48 in Memory management

Download history 130011/week @ 2024-07-01 119234/week @ 2024-07-08 121681/week @ 2024-07-15 127209/week @ 2024-07-22 128379/week @ 2024-07-29 105417/week @ 2024-08-05 90055/week @ 2024-08-12 92677/week @ 2024-08-19 90095/week @ 2024-08-26 78438/week @ 2024-09-02 81107/week @ 2024-09-09 80978/week @ 2024-09-16 86214/week @ 2024-09-23 83826/week @ 2024-09-30 80285/week @ 2024-10-07 79749/week @ 2024-10-14

332,546 downloads per month
Used in 135 crates (5 directly)

MIT license

18KB
376 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