Struct LsmFile

Source
pub struct LsmFile<T, K>
where T: Read + Write + Seek, K: Key,
{ /* private fields */ }
Expand description

LSM Abstraction over something File like (i.e. implementing Read, Write, and Seek).

This type maintains a write cache in memory, and you must call the flush method for the changes to be persisted. This type will not automatically flush.l

Implementations§

Source§

impl<T, K> LsmFile<T, K>
where T: Read + Write + Seek, K: Key,

Source

pub fn new( file: T, compression: Option<i32>, key: Arc<K>, max_cache_entries: Option<usize>, ) -> Result<Self, BackendError>

Creates a new LsmFile from the provided, already existing, File like object.

Accepts values for the compression level for the file, the key to be used for encryption/decryption, as well as the maximum number of cache entries before a mandatory flush occurs, which defaults to 100.

§Errors
  • Error::EntryIO if an error occurs while reading the entries
  • Will bubble up any segment errors`
Source

pub fn get<C, V>(&mut self, key: &C) -> Result<Option<V>, BackendError>

Retries a value from the store given a key, if the value exists in the store.

The most recently inserted version of the value will be returned

§Errors

Will return an error if any IO error occurs, or if the value fails to deserialize.

Source

pub fn insert<C, V>(&mut self, key: &C, value: &V) -> Result<(), BackendError>
where C: Serialize, V: Serialize,

Inserts an object into the store

This method will write to the cache, however, if this insertion makes the cache size greater than or equal to the maximum number of entries, the current cache will be flushed.

§Errors
  • Will return an error if either the key or value fail to serialize
  • Will bubble up any IO errors that occur, if a flush occurs
Source

pub fn flush(&mut self) -> Result<(), BackendError>

Flushes the cache to disk

§Errors

Will bubble up any IO errors

Source

pub fn to_hashmap<C, V>(&mut self) -> Result<HashMap<C, V>, BackendError>

Converts the current contents of the store to a HashMap.

Iterates through this LsmFIle’s keys, and insert them all into the returned HashMap. The most up to date value will be used for each key.

§Errors

Will bubble up any error that occurs during a get operation

Source

pub fn to_pairs<C, V>(&mut self) -> Result<Vec<(C, V)>, BackendError>

Converts the current contents of the store to a Vec of pairs.

Iterates through this LsmFIle’s keys, and insert them all into the returned Vec]. The most up to date value will be used for each key.

§Errors

Will bubble up any error that occurs during a get operation

Source

pub fn into_inner(self) -> T

Consumes self and returns the inner File like object

Source§

impl<K> LsmFile<File, K>
where K: Key,

Source

pub fn open( path: impl AsRef<Path> + Debug, compression: Option<i32>, key: Arc<K>, max_cache_entries: Option<usize>, ) -> Result<Self, BackendError>

Opens an existing LsmFile from the provided path.

Will open the file in read/write mode. Will fail if the file does not exists.

§Errors
  • If the file does not exist
  • If any other IO occurs
  • If any of the decryption or deserialization of control structures fails
Source

pub fn create( path: impl AsRef<Path> + Debug, compression: Option<i32>, key: Arc<K>, max_cache_entries: Option<usize>, ) -> Result<Self, BackendError>

Opens an existing LsmFile from the provided path.

Will create the file in read/write mode, failing if the file exists

§Errors
  • If the file already exists
  • If any other IO occurs

Auto Trait Implementations§

§

impl<T, K> Freeze for LsmFile<T, K>
where T: Freeze,

§

impl<T, K> RefUnwindSafe for LsmFile<T, K>

§

impl<T, K> Send for LsmFile<T, K>
where T: Send, K: Sync + Send,

§

impl<T, K> Sync for LsmFile<T, K>
where T: Sync, K: Sync + Send,

§

impl<T, K> Unpin for LsmFile<T, K>
where T: Unpin,

§

impl<T, K> UnwindSafe for LsmFile<T, K>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more