https://github.com/lbfalvy/intern-all
A safe and leak-free interner for data of mixed and arbitrary type
https://github.com/lbfalvy/intern-all
langdev nounsafe parsing strings
Last synced: about 2 months ago
JSON representation
A safe and leak-free interner for data of mixed and arbitrary type
- Host: GitHub
- URL: https://github.com/lbfalvy/intern-all
- Owner: lbfalvy
- Created: 2023-11-18T13:52:47.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-27T17:13:17.000Z (about 2 years ago)
- Last Synced: 2025-12-19T21:55:03.883Z (4 months ago)
- Topics: langdev, nounsafe, parsing, strings
- Language: Rust
- Homepage: https://docs.rs/intern-all/latest/intern_all/
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
An interner for data of mixed / arbitrary type. It uses weak references and the default allocator so it can be used in long-running processes.
```rust
use std::env;
use std::path::PathBuf;
use intern_all::{i, Tok};
// Intern a value
let a: Tok = i("foo");
// Intern a path
let b: Tok = i(&env::current_dir().unwrap());
```
Some convenience methods are also provided to make working with lists easier
```rust
use intern_all::{i, ibv, iv, Tok};
// Intern a list as a slice of tokens
let v1: Tok>> = i(&[i("bar"), i("quz"), i("quux")][..]);
// Intern a list of internable values
let v2: Tok>> =
iv(["bar".to_string(), "quz".to_string(), "quux".to_string()]);
// Intern a list of the borrowed form of internable values
let v3: Tok>> = ibv(["bar", "quz", "quux"]);
assert!(v1 == v2 && v2 == v3)
```
The interner uses weak references but the unreferenced values still take up
space in the token table. To avoid a memory leak, you can periodically
sremove entries referring to unreferenced values from the interner with
`sweep` or `sweep_t`.
```rust
use intern_all::{sweep, sweep_t};
// use this for general housekeeping
sweep();
// use this if a lot of temporary values of a particular interned type
// had been dropped recently
sweep_t::();
```