Skip to main content

FuseWriter

Struct FuseWriter 

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

Builds a .fsdb file.

An object is stored once; any number of keys may point at it. That is the whole point of the format — a million keys sharing one payload cost one copy on disk.

§Example

use fusedb::FuseWriter;
use std::collections::BTreeMap;

let mut w = FuseWriter::new();

let mut google = BTreeMap::new();
google.insert("company", "Google");

// one object, three keys
let oid = w.add_object(&google)?;
w.add_key("google.com", oid)?;
w.add_key("8.8.8.8", oid)?;
w.add_key("8.8.4.4", oid)?;

w.build("db.fsdb")?;

§Deduplication

add_object always appends a new object, exactly like the Python FuseWriter. Use add_object_deduped when you want identical payloads collapsed into a single stored object.

Implementations§

Source§

impl FuseWriter

Source

pub fn new() -> Self

Create a new, empty writer.

Source

pub fn add_object_raw(&mut self, raw: impl AsRef<[u8]>) -> usize

Store pre-encoded bytes as a new object. Returns its object ID.

The bytes are written to disk verbatim. If you want the file to be readable by the Python package, they must be MessagePack — which is what add_object produces for you.

Source

pub fn add_object_raw_deduped(&mut self, raw: impl AsRef<[u8]>) -> usize

Store pre-encoded bytes, reusing an existing object when the payload is byte-identical to one already added through this method.

Source

pub fn add_key( &mut self, key: impl AsRef<[u8]>, obj_id: usize, ) -> FuseResult<()>

Map key to an existing object ID.

Keys are arbitrary byte strings — UTF-8 text, binary, packed IPs. Adding the same key twice overwrites the earlier mapping.

§Errors

FuseError::InvalidArg if obj_id was never returned by an add_object* call, or if key is longer than MAX_KEY_LEN bytes.

Source

pub fn add_raw( &mut self, key: impl AsRef<[u8]>, raw: impl AsRef<[u8]>, ) -> FuseResult<usize>

Store raw bytes and point key at them, in one call.

Source

pub fn add_object<T: Serialize + ?Sized>( &mut self, value: &T, ) -> FuseResult<usize>

Serialise value to MessagePack and store it as a new object.

The encoding matches Python’s msgpack.packb(value, use_bin_type=True), so anything written here decodes in the Python package unchanged.

Source

pub fn add_object_deduped<T: Serialize + ?Sized>( &mut self, value: &T, ) -> FuseResult<usize>

Like add_object, but collapses values that encode to identical bytes into a single stored object.

Source

pub fn add<T: Serialize + ?Sized>( &mut self, key: impl AsRef<[u8]>, value: &T, ) -> FuseResult<usize>

Convenience: add_object + add_key.

Source

pub fn build(&self, path: impl AsRef<Path>) -> FuseResult<BuildReport>

Write the .fsdb file atomically: tmp → fsync → rename.

Readers holding the previous file open keep seeing consistent data through their existing mmap.

Source

pub fn num_objects(&self) -> usize

Objects staged so far.

Source

pub fn num_keys(&self) -> usize

Keys staged so far.

Source

pub fn is_empty(&self) -> bool

Is the writer empty?

Trait Implementations§

Source§

impl Debug for FuseWriter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FuseWriter

Source§

fn default() -> Self

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.