mirror of
https://github.com/danog/parser.git
synced 2025-01-22 13:01:32 +01:00
interner: README
This commit is contained in:
parent
d6fb3663cc
commit
10b3e86248
18
trunk_interner/README.md
Normal file
18
trunk_interner/README.md
Normal file
@ -0,0 +1,18 @@
|
||||
# Interner
|
||||
|
||||
This crate provides a simple string interner through the `Interner` structure. This structure allows you to retrieve a unique `Symbol` to a `&str`.
|
||||
|
||||
## Usage
|
||||
|
||||
```rust
|
||||
use trunk_interner::{Interner, Symbol};
|
||||
|
||||
fn main() {
|
||||
let mut interner = Interner::default();
|
||||
|
||||
let my_string_symbol: Symbol = interner.intern("Hello, world!");
|
||||
let my_original_string: &str = interner.get(my_string_symbol);
|
||||
}
|
||||
```
|
||||
|
||||
If a `&str` is interned multiple times, the same `Symbol` will be returned, in theory minimizing the amount of memory used by your program due to a reduced number of `String` allocations.
|
Loading…
x
Reference in New Issue
Block a user