pub struct Rustcask { /* private fields */ }Expand description
A handle to interact with a Rustcask storage engine.
Implementations§
Source§impl Rustcask
impl Rustcask
Sourcepub fn builder() -> RustcaskBuilder
pub fn builder() -> RustcaskBuilder
Returns a Rustcask builder with default configuration values.
Sourcepub fn set(&mut self, key: Vec<u8>, value: Vec<u8>) -> Result<(), SetError>
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 aVec<u8>.value- The value to associate with the key, as aVec<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
LogFileEntrycould 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.
Sourcepub fn get<'a>(
&'a mut self,
key: &'a Vec<u8>,
) -> Result<Option<Vec<u8>>, GetError<'a>>
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 theVec<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 aVec<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.
Sourcepub fn remove(&mut self, key: Vec<u8>) -> Result<Option<Vec<u8>>, RemoveError>
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 aVec<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.
Sourcepub fn merge(&mut self) -> Result<(), MergeError>
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. Themerge_generationfield 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.