JsonMutexDB

Struct JsonMutexDB 

Source
pub struct JsonMutexDB { /* private fields */ }

Implementations§

Source§

impl JsonMutexDB

Source

pub fn new( path: &str, pretty: bool, async_updates: bool, fast_serialization: bool, ) -> Result<Self, DbError>

Creates a new instance of JsonMutexDB.

§Errors

This function will return an error if the specified file cannot be read, if the JSON data is invalid, or if there are issues with file I/O operations.

Source

pub fn get(&self) -> Result<Value, DbError>

Returns a clone of the JSON data. If async_updates is enabled, fetches the latest state from the background thread.

§Errors

This function will return an error if:

  • The background thread fails to send or receive data in async mode.
  • The mutex is poisoned in sync mode.
  • The database is in an invalid state (neither sync nor async mode).
Source

pub fn update<F>(&self, update_fn: F) -> Result<(), DbError>
where F: FnOnce(&mut Value) + Send + 'static,

Updates the JSON data. If async_updates is enabled, sends the update closure to the background thread. Otherwise, applies the update synchronously. Updates the JSON data.

If async_updates is enabled, sends the update closure to the background thread. Otherwise, applies the update synchronously.

§Errors

This function will return an error if:

  • The background thread fails to send the update task in async mode.
  • The mutex is poisoned in sync mode.
  • The database is in an invalid state (neither sync nor async mode).
Source

pub fn save_sync(&self) -> Result<(), DbError>

Synchronously saves the current JSON data to disk atomically. If async_updates is enabled, fetches the latest state before saving.

§Errors

This function will return an error if:

  • The current state cannot be fetched (e.g., due to background thread issues in async mode).
  • There are file I/O errors during the save operation.
Source

pub fn save_async(&self) -> Result<(), DbError>

Asynchronously saves the current JSON data atomically. If async_updates is enabled, fetches the latest state first, then spawns the save thread. Asynchronously saves the current JSON data atomically.

If async_updates is enabled, fetches the latest state first, then spawns the save thread.

§Errors

This function will return an error if:

  • The current state cannot be fetched (e.g., due to background thread issues in async mode).
  • There are file I/O errors during the save operation.

Trait Implementations§

Source§

impl Drop for JsonMutexDB

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl RefUnwindSafe for JsonMutexDB

Source§

impl UnwindSafe for JsonMutexDB

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

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.