Struct Rustcask

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

A handle to interact with a Rustcask storage engine.

Implementations§

Source§

impl Rustcask

Source

pub fn builder() -> RustcaskBuilder

Returns a Rustcask builder with default configuration values.

Source

pub fn set(&mut self, key: Vec<u8>, value: Vec<u8>) -> Result<(), SetError>

Inserts a key-value pair into Rustcask.

§Arguments
  • key - The key to insert, as a Vec<u8>.
  • value - The value to associate with the key, as a Vec<u8>.
§Returns
  • Ok(()) if the key-value pair was successfully inserted.
  • Err(SetError) if there was an error serializing the entry or writing to the data file.
§Errors

This function may return a SetError if:

  • The LogFileEntry could not be serialized (SetErrorKind::Serialize).
  • There was an error writing to the active data file.
§Panics

This function will panic if another thread crashed while holding the lock on the key directory.

Source

pub fn get<'a>( &'a mut self, key: &'a Vec<u8>, ) -> Result<Option<Vec<u8>>, GetError<'a>>

Returns a reference to the value corresponding to the key.

§Arguments
  • key - A reference to the Vec<u8> representing the key to look up.
§Returns
  • Ok(Some(value)) - If the key is found in the data store, returns the corresponding value as a Vec<u8>.
  • Ok(None) - If the key is not found in the data store.
  • Err(GetError) - If an error occurs while reading or deserializing the data from the data store.
§Errors

This function may return a GetError with the following variants:

  • GetErrorKind::Io(err) - An I/O error occurred while reading the data file.
  • GetErrorKind::Deserialize(err) - An error occurred while deserializing the data from the data file.
Source

pub fn remove(&mut self, key: Vec<u8>) -> Result<Option<Vec<u8>>, RemoveError>

Removes a key-value pair from the database.

This function takes a key as input and removes the corresponding key-value pair from the database. If the key exists, it returns the previously associated value. If the key does not exist, it returns None.

§Arguments
  • key - The key to remove, as a Vec<u8>.
§Returns
  • Ok(Some(value)) if the key existed and was removed, containing the previously associated value.
  • Ok(None) if the key did not exist in the database.
  • Err(RemoveError) if there was an error removing the key.
§Errors

This function may return a RemoveError if:

  • There was an I/O error seeking or reading from the data file (RemoveErrorKind::Io).
  • There was an error deserializing the log entry from the data file (RemoveErrorKind::Deserialize).
§Panics

This function will panic if another thread crashed while holding the lock on the key directory.

Source

pub fn merge(&mut self) -> Result<(), MergeError>

Compacts the rustcask directory be writing active key-value pairs to a new set of data files, and removes old data files which may have contained dead values.

§Errors

This function may return a MergeError with the following variants:

  • MergeErrorKind::OutsideMergeWindow - The merge operation was attempted outside of the allowed merge window. The merge_generation field in this case indicates the next generation number when a merge will be allowed.
  • MergeErrorKind::Io(err) - An I/O error occurred while reading or writing data files during the merge operation.

Reads can be performed concurrently with merges. However, writes will be blocked until the merge is complete.

Trait Implementations§

Source§

impl Clone for Rustcask

Source§

fn clone(&self) -> Rustcask

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rustcask

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.