https://github.com/quickwit-oss/census
Rust crate to keep a list of all of your living objects.
https://github.com/quickwit-oss/census
Last synced: 7 months ago
JSON representation
Rust crate to keep a list of all of your living objects.
- Host: GitHub
- URL: https://github.com/quickwit-oss/census
- Owner: quickwit-oss
- License: mit
- Created: 2018-06-29T01:24:20.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-01-26T10:30:52.000Z (over 2 years ago)
- Last Synced: 2025-04-15T07:15:40.149Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 28.3 KB
- Stars: 8
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Census
[](https://ci.appveyor.com/project/fulmicoton/census/branch/master)
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` instance include some reference counting logic to ensure that
the object is removed from the inventory once the last instance is dropped.
# Example
```rust
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` 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> = inventory.list();
assert_eq!(living_instances.len(), 2);
}
```