Skip to main content

Builder

Struct Builder 

Source
pub struct Builder { /* private fields */ }
Expand description

Accumulates (key, value) pairs and serializes a minimal FSA.

Implementations§

Source§

impl Builder

Source

pub fn new() -> Self

Construct an empty builder. Call insert to add entries, then finish to serialize.

Source

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));
Source

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§

Source§

impl Default for Builder

Source§

fn default() -> Builder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.