census

Crates.iocensus
lib.rscensus
version0.4.2
sourcesrc
created_at2018-06-29 01:28:55.932739
updated_at2024-01-26 10:31:09.935792
descriptionKeeps an inventory of living objects
homepagehttps://github.com/quickwit-inc/census
repositoryhttps://github.com/quickwit-inc/census
max_upload_size
id72178
size20,685
Paul Masurel (fulmicoton)

documentation

README

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);
}
Commit count: 21

cargo fmt