pub struct CrdtState { /* private fields */ }Expand description
A CRDT state for a single tenant/namespace.
Implementations§
Source§impl CrdtState
impl CrdtState
Sourcepub fn upsert_versioned(
&self,
collection: &str,
row_id: &str,
fields: &[(&str, LoroValue)],
) -> Result<()>
pub fn upsert_versioned( &self, collection: &str, row_id: &str, fields: &[(&str, LoroValue)], ) -> Result<()>
Upsert a row with prior-version archiving for bitemporal
collections. When a row with row_id already exists and carries
a finite _ts_system, its field map is copied into the
bitemporal history sibling before the new fields overwrite the
live row. Non-bitemporal callers should stay on
CrdtState::upsert — the archive has a non-trivial doc-size
cost and is only meaningful when the collection participates in
AS OF / audit queries.
Sourcepub fn read_row_as_of(
&self,
collection: &str,
row_id: &str,
asof_ms: i64,
) -> Option<LoroValue>
pub fn read_row_as_of( &self, collection: &str, row_id: &str, asof_ms: i64, ) -> Option<LoroValue>
Read the row as it was at asof_ms (system-time). Scans the
archive for the highest sys_ms <= asof_ms; falls back to the
current row when its _ts_system <= asof_ms; returns None
when no version existed at or before the requested time.
Sourcepub fn archive_version_count(&self, collection: &str, row_id: &str) -> usize
pub fn archive_version_count(&self, collection: &str, row_id: &str) -> usize
Count archived versions for a row (live row excluded). Primarily for tests and operational introspection.
Sourcepub fn purge_history_before(
&self,
collection: &str,
cutoff_ms: i64,
) -> Result<usize>
pub fn purge_history_before( &self, collection: &str, cutoff_ms: i64, ) -> Result<usize>
Drop archived versions with sys_ms < cutoff_ms for the given
collection. Returns the number of archive entries deleted. The
live row is never touched — retention only reclaims history, so
the current state of every logical row remains readable even
when the entire archive is pruned.
Source§impl CrdtState
impl CrdtState
Sourcepub fn register_array_surrogate(&mut self, id: String)
pub fn register_array_surrogate(&mut self, id: String)
Register an array-engine surrogate ID as a valid referent for FK checks.
Call this before running constraint validation whenever the referent
collection is backed by the array engine rather than the document/graph
engines. The ID must be the string form of the surrogate (e.g., the
decimal representation of the Surrogate value or the composite key
used by the array catalog).
Sourcepub fn upsert(
&self,
collection: &str,
row_id: &str,
fields: &[(&str, LoroValue)],
) -> Result<()>
pub fn upsert( &self, collection: &str, row_id: &str, fields: &[(&str, LoroValue)], ) -> Result<()>
Insert or update a row in a collection.
Sourcepub fn delete(&self, collection: &str, row_id: &str) -> Result<()>
pub fn delete(&self, collection: &str, row_id: &str) -> Result<()>
Delete a row from a collection.
Sourcepub fn clear_collection(&self, collection: &str) -> Result<usize>
pub fn clear_collection(&self, collection: &str) -> Result<usize>
Delete all rows in a collection. Returns the number of rows deleted.
Sourcepub fn read_row(&self, collection: &str, row_id: &str) -> Option<LoroValue>
pub fn read_row(&self, collection: &str, row_id: &str) -> Option<LoroValue>
Read a single row’s fields as a LoroValue::Map.
Navigates via LoroMap::get() to avoid the expensive recursive
get_deep_value() clone on the entire row container.
Sourcepub fn read_field(
&self,
collection: &str,
row_id: &str,
field: &str,
) -> Option<LoroValue>
pub fn read_field( &self, collection: &str, row_id: &str, field: &str, ) -> Option<LoroValue>
Read a single field from a row without cloning the entire row.
This is the fast path for KV-style access where only one field is needed. Avoids allocating a full Map for single-field reads.
Shares the same doc.get_map(collection).get(row_id) lookup pattern
as read_row, but returns a single field value instead of the whole
row map — different return granularity, intentionally kept separate.
Sourcepub fn row_exists(&self, collection: &str, row_id: &str) -> bool
pub fn row_exists(&self, collection: &str, row_id: &str) -> bool
Check if a row exists in a collection.
Checks the Loro-backed document/graph collections first. If not found
there, falls back to the registered array surrogate set so that
BiTemporalFK and ForeignKey constraints can reference array-engine
cells as valid referents without requiring a full cross-engine query.
Sourcepub fn collection_names(&self) -> Vec<String>
pub fn collection_names(&self) -> Vec<String>
List all collection names (top-level map keys in the Loro doc).
Sourcepub fn field_value_exists(
&self,
collection: &str,
field: &str,
value: &LoroValue,
) -> bool
pub fn field_value_exists( &self, collection: &str, field: &str, value: &LoroValue, ) -> bool
Check if a value exists for the given field across all rows in a collection. Used for UNIQUE constraint checking.
Sourcepub fn field_value_exists_live(
&self,
collection: &str,
field: &str,
value: &LoroValue,
) -> bool
pub fn field_value_exists_live( &self, collection: &str, field: &str, value: &LoroValue, ) -> bool
Bitemporal variant of [field_value_exists]: only considers rows
whose _ts_valid_until is open (absent or i64::MAX).
A UNIQUE collision between a superseded version and a new live row is not a violation — both may share the same value because they represent the same logical entity at different valid-times.
Sourcepub fn live_row_ids(&self, collection: &str) -> Vec<String>
pub fn live_row_ids(&self, collection: &str) -> Vec<String>
Return row IDs currently “live” in a bitemporal collection
(rows whose _ts_valid_until is open). For non-bitemporal
collections every row is returned.
Source§impl CrdtState
impl CrdtState
Sourcepub fn oplog_version_vector(&self) -> VersionVector
pub fn oplog_version_vector(&self) -> VersionVector
Get the current oplog version vector.
Sourcepub fn read_at_version(
&self,
collection: &str,
row_id: &str,
version: &VersionVector,
) -> Result<Option<LoroValue>>
pub fn read_at_version( &self, collection: &str, row_id: &str, version: &VersionVector, ) -> Result<Option<LoroValue>>
Read the document state at a historical version.
Uses fork_at to create a lightweight copy at the target version
and reads the specified row. Returns None if the row didn’t exist.
Cost: O(oplog_size) for the fork — not for hot-path queries.
Sourcepub fn export_updates_since(
&self,
from_version: &VersionVector,
) -> Result<Vec<u8>>
pub fn export_updates_since( &self, from_version: &VersionVector, ) -> Result<Vec<u8>>
Export the oplog delta from a version to the current state.
Returns the operations that transform from_version into current state.
Used for DIFF rendering and delta sync.
Sourcepub fn compact_at_version(&mut self, version: &VersionVector) -> Result<()>
pub fn compact_at_version(&mut self, version: &VersionVector) -> Result<()>
Compact history at a specific version (not just current frontiers).
Discards oplog entries before the target version. Current state and all versions after the target are preserved.
Sourcepub fn restore_to_version(
&self,
collection: &str,
row_id: &str,
version: &VersionVector,
) -> Result<Vec<u8>>
pub fn restore_to_version( &self, collection: &str, row_id: &str, version: &VersionVector, ) -> Result<Vec<u8>>
Restore a document to a historical version by creating a forward delta.
Reads the state at the target version, then generates a new mutation that sets the current state to match the historical state. History is preserved — this is a forward operation, not a rollback.
Returns the delta bytes to be applied through the normal write path.
Source§impl CrdtState
impl CrdtState
Sourcepub fn export_snapshot(&self) -> Result<Vec<u8>>
pub fn export_snapshot(&self) -> Result<Vec<u8>>
Export the current state as bytes for sync.
Sourcepub fn compact_history(&mut self) -> Result<()>
pub fn compact_history(&mut self) -> Result<()>
Compact the CRDT history by replacing the internal LoroDoc with a shallow snapshot.
A shallow snapshot contains the current state but discards the full operation history. This is the CRDT equivalent of WAL truncation after checkpoint.
After compaction:
- All current state is preserved (reads return same values).
- New deltas can still be applied and merged.
- Historical operations before the snapshot point are gone.
- Peers that sync after compaction receive a full snapshot instead of incremental deltas (acceptable for long-offline peers).
Call this periodically (e.g., every 30 minutes or when memory pressure exceeds threshold) to prevent unbounded history growth.
Sourcepub fn estimated_memory_bytes(&self) -> usize
pub fn estimated_memory_bytes(&self) -> usize
Estimated memory usage of the CRDT state (bytes).
Includes operation history, current state, and internal caches.
Use this to decide when to trigger compact_history().
Auto Trait Implementations§
impl Freeze for CrdtState
impl RefUnwindSafe for CrdtState
impl Send for CrdtState
impl Sync for CrdtState
impl Unpin for CrdtState
impl UnsafeUnpin for CrdtState
impl UnwindSafe for CrdtState
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.