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
impl FuseWriter
Sourcepub fn add_object_raw(&mut self, raw: impl AsRef<[u8]>) -> usize
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.
Sourcepub fn add_object_raw_deduped(&mut self, raw: impl AsRef<[u8]>) -> usize
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.
Sourcepub fn add_key(
&mut self,
key: impl AsRef<[u8]>,
obj_id: usize,
) -> FuseResult<()>
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.
Sourcepub fn add_raw(
&mut self,
key: impl AsRef<[u8]>,
raw: impl AsRef<[u8]>,
) -> FuseResult<usize>
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.
Sourcepub fn add_object<T: Serialize + ?Sized>(
&mut self,
value: &T,
) -> FuseResult<usize>
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.
Sourcepub fn add_object_deduped<T: Serialize + ?Sized>(
&mut self,
value: &T,
) -> FuseResult<usize>
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.
Sourcepub fn add<T: Serialize + ?Sized>(
&mut self,
key: impl AsRef<[u8]>,
value: &T,
) -> FuseResult<usize>
pub fn add<T: Serialize + ?Sized>( &mut self, key: impl AsRef<[u8]>, value: &T, ) -> FuseResult<usize>
Convenience: add_object + add_key.
Sourcepub fn build(&self, path: impl AsRef<Path>) -> FuseResult<BuildReport>
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.
Sourcepub fn num_objects(&self) -> usize
pub fn num_objects(&self) -> usize
Objects staged so far.