Skip to main content

MemoryStorage

Struct MemoryStorage 

Source
pub struct MemoryStorage { /* private fields */ }
Expand description

In-memory CRDT storage for testing.

This implementation stores all data in memory using HashMap and Vec. It’s thread-safe via RwLock but data is lost when dropped.

Auto-compaction is triggered when the number of updates for a document exceeds [AUTO_COMPACT_THRESHOLD], keeping the most recent [AUTO_COMPACT_KEEP] updates.

Implementations§

Source§

impl MemoryStorage

Source

pub fn new() -> Self

Create a new empty in-memory storage.

Trait Implementations§

Source§

impl CrdtStorage for MemoryStorage

Source§

fn load_doc(&self, name: &str) -> StorageResult<Option<Vec<u8>>>

Load the full document state as a binary blob. Read more
Source§

fn save_doc(&self, name: &str, state: &[u8]) -> StorageResult<()>

Save the full document state. Read more
Source§

fn delete_doc(&self, name: &str) -> StorageResult<()>

Delete a document and all its updates.
Source§

fn list_docs(&self) -> StorageResult<Vec<String>>

List all document names in storage.
Source§

fn append_update_with_device( &self, name: &str, update: &[u8], origin: UpdateOrigin, device_id: Option<&str>, device_name: Option<&str>, ) -> StorageResult<i64>

Append an incremental update with device attribution. Read more
Source§

fn get_updates_since( &self, name: &str, since_id: i64, ) -> StorageResult<Vec<CrdtUpdate>>

Get all updates for a document since a given update ID. Read more
Source§

fn get_all_updates(&self, name: &str) -> StorageResult<Vec<CrdtUpdate>>

Get all updates for a document.
Source§

fn get_state_at( &self, name: &str, update_id: i64, ) -> StorageResult<Option<Vec<u8>>>

Get the state of a document at a specific point in history. Read more
Source§

fn compact(&self, name: &str, keep_updates: usize) -> StorageResult<()>

Compact old updates into the document snapshot. Read more
Source§

fn get_latest_update_id(&self, name: &str) -> StorageResult<i64>

Get the latest update ID for a document. Read more
Source§

fn rename_doc(&self, old_name: &str, new_name: &str) -> StorageResult<()>

Rename a document by copying its state and updates to a new name. Read more
Source§

fn clear_updates(&self, name: &str) -> StorageResult<()>

Clear all updates for a document while keeping the snapshot. Read more
Source§

fn append_update( &self, name: &str, update: &[u8], origin: UpdateOrigin, ) -> StorageResult<i64>

Append an incremental update to the update log. Read more
Source§

fn batch_append_updates( &self, updates: &[(&str, &[u8], UpdateOrigin)], ) -> StorageResult<Vec<i64>>

Append multiple updates atomically. Read more
Source§

impl Debug for MemoryStorage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MemoryStorage

Source§

fn default() -> MemoryStorage

Returns the “default value” for a type. 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> 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.
Source§

impl<M> Meta for M
where M: Default + Send + Sync,