pub struct AcidJson<T: Serialize + DeserializeOwned + Sync> { /* private fields */ }
Expand description
A “smart pointer” to a JSON file on disk. Can be used in a RwLock-like fashion for thread-safe, ACID-guaranteed updates to the underlying file. Is “Arc-like” can can be cheaply cloned to create more references to the same file.
Implementations§
Source§impl<T: Serialize + DeserializeOwned + Sync> AcidJson<T>
impl<T: Serialize + DeserializeOwned + Sync> AcidJson<T>
Sourcepub fn open(fname: &Path) -> Result<Self, AcidJsonError>
pub fn open(fname: &Path) -> Result<Self, AcidJsonError>
Opens an AcidJson.
Sourcepub fn open_or_else(
fname: &Path,
gen_def: impl FnOnce() -> T,
) -> Result<Self, AcidJsonError>
pub fn open_or_else( fname: &Path, gen_def: impl FnOnce() -> T, ) -> Result<Self, AcidJsonError>
Opens an AcidJson, with a default value if the file does not yet exist.
Sourcepub fn read(&self) -> AcidJsonReadGuard<'_, T>
pub fn read(&self) -> AcidJsonReadGuard<'_, T>
Read-locks the AcidJson.
Sourcepub fn write(&self) -> AcidJsonWriteGuard<'_, T>
pub fn write(&self) -> AcidJsonWriteGuard<'_, T>
Write-locks the AcidJson.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for AcidJson<T>
impl<T> RefUnwindSafe for AcidJson<T>
impl<T> Send for AcidJson<T>where
T: Send,
impl<T> Sync for AcidJson<T>where
T: Send,
impl<T> Unpin for AcidJson<T>
impl<T> UnwindSafe for AcidJson<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more