pub struct Builder { /* private fields */ }Expand description
Accumulates (key, value) pairs and serializes a minimal FSA.
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn insert(&mut self, key: &[u8], value: u64)
pub fn insert(&mut self, key: &[u8], value: u64)
Add a key→value entry. Duplicate keys: last insert wins. Keys may be inserted in any order (the builder sorts).
use inputx_fsa::{Builder, Fsa};
let mut b = Builder::new();
b.insert(b"banana", 4);
b.insert(b"apple", 1); // arbitrary order is fine
b.insert(b"apple", 99); // last-write-wins on duplicates
let fsa = Fsa::new(b.finish()).unwrap();
assert_eq!(fsa.get(b"apple"), Some(99));Sourcepub fn finish(self) -> Vec<u8> ⓘ
pub fn finish(self) -> Vec<u8> ⓘ
Consume the builder and return the serialized FSA bytes.
The output is a self-contained byte buffer — embed via
include_bytes!, mmap, or load from disk; either way pass it
directly to Fsa::new.
use inputx_fsa::{Builder, Fsa};
let mut b = Builder::new();
for (k, v) in [(&b"a"[..], 1u64), (b"b", 2), (b"c", 3)] {
b.insert(k, v);
}
let bytes: Vec<u8> = b.finish();
let fsa = Fsa::new(&bytes[..]).unwrap();
assert_eq!(fsa.len(), 3);Trait Implementations§
Auto Trait Implementations§
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnsafeUnpin for Builder
impl UnwindSafe for Builder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more