Struct safina_db::storage::Storage

source ·
pub struct Storage {
    pub file: Option<File>,
    /* private fields */
}

Fields§

§file: Option<File>

Implementations§

source§

impl Storage

source

pub fn new(file_path: Option<&str>) -> Self

Creates a new Storage instance with an optional file path.

§Arguments
  • file_path - An optional string slice that holds the file path.
§Returns
  • A new instance of Storage.
source

pub fn load_file( &mut self, file_path: Option<&str> ) -> Result<Vec<KV>, Box<dyn Error>>

Loads the file from the specified or existing file path and deserializes the content.

§Arguments
  • file_path - An optional string slice that holds the file path.
§Returns
  • Ok(Vec<KV>) - A vector of deserialized KV structs if the operation is successful.
  • Box<dyn Error>> - An error message if the operation fails.
source

pub fn save_file(&mut self, data: Vec<KV>) -> Result<(), Box<dyn Error>>

Saves the provided data to the file by serializing it into binary format.

§Arguments
  • data - A vector of KV structs to be serialized and saved.
§Returns
  • Ok(()) - If the operation is successful.
  • Err(Box<dyn Error>) - An error message if the operation fails.

Trait Implementations§

source§

impl Debug for Storage

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> 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>,

§

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>,

§

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.