Skip to main content

Persistent

Struct Persistent 

Source
pub struct Persistent<T>
where T: Merge + Serialize + DeserializeOwned + Clone + Default + Send + 'static,
{ /* private fields */ }
Expand description

A persistent CRDT wrapper with journaling (native platform).

Wraps any type implementing Merge + Serialize + DeserializeOwned and provides durable storage with crash recovery.

This is the native version with Send bounds required for thread-safe access. The WASM version relaxes these bounds since JavaScript is single-threaded.

Implementations§

Source§

impl<T> Persistent<T>
where T: Merge + Serialize + DeserializeOwned + Clone + Default + Send + 'static,

Native implementation with Send bounds.

Source

pub async fn mount( vfs: Arc<dyn Vfs + Send + Sync>, path: &str, ) -> VfsResult<Self>

Mount a persistent value from a journal file.

If the journal exists, replays all entries to reconstruct state. If not, creates a new journal with default state.

Source

pub async fn get(&self) -> T

Get immutable access to the current state.

Source

pub async fn mutate<F, R>(&self, f: F) -> VfsResult<R>
where F: FnOnce(&mut T) -> R + Send,

Mutate the state and persist the delta.

Source

pub async fn compact(&self) -> VfsResult<()>

Compact the journal by writing a snapshot.

Source

pub async fn entry_count(&self) -> u64

Get the number of journal entries.

Source

pub async fn maybe_compact(&self, threshold: u64) -> VfsResult<bool>

Automatically compact when entry count exceeds threshold.

Auto Trait Implementations§

§

impl<T> Freeze for Persistent<T>

§

impl<T> !RefUnwindSafe for Persistent<T>

§

impl<T> Send for Persistent<T>

§

impl<T> Sync for Persistent<T>
where T: Sync,

§

impl<T> Unpin for Persistent<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Persistent<T>

§

impl<T> !UnwindSafe for Persistent<T>

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> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,