pub struct CrdtDoc { /* private fields */ }Expand description
A CRDT document synchronized across the mesh.
Wraps a Loro LoroDoc with automatic background sync. Local changes
are broadcast to peers; remote changes are merged automatically via
Loro’s CRDT algorithms.
Created via CrdtDoc::new or Node::crdt_doc.
Implementations§
Source§impl CrdtDoc
impl CrdtDoc
Sourcepub async fn new<N: NetworkProvider + 'static>(
node: Arc<Node<N>>,
doc_id: &str,
) -> Result<Arc<Self>, CrdtDocError>
pub async fn new<N: NetworkProvider + 'static>( node: Arc<Node<N>>, doc_id: &str, ) -> Result<Arc<Self>, CrdtDocError>
Create a new CrdtDoc and start the background sync task.
Uses the default MemoryCrdtBackend (no persistence).
Sourcepub async fn new_with_backend<N: NetworkProvider + 'static>(
node: Arc<Node<N>>,
doc_id: &str,
backend: Arc<dyn CrdtBackend>,
) -> Result<Arc<Self>, CrdtDocError>
pub async fn new_with_backend<N: NetworkProvider + 'static>( node: Arc<Node<N>>, doc_id: &str, backend: Arc<dyn CrdtBackend>, ) -> Result<Arc<Self>, CrdtDocError>
Create a new CrdtDoc with a custom persistence backend.
On startup, attempts to restore from the backend: first loads the snapshot (if any), then replays incremental updates on top.
Sourcepub fn movable_list(&self, name: &str) -> LoroMovableList
pub fn movable_list(&self, name: &str) -> LoroMovableList
Get a LoroMovableList container by name.
Sourcepub fn counter(&self, name: &str) -> LoroCounter
pub fn counter(&self, name: &str) -> LoroCounter
Get a LoroCounter container by name.
Sourcepub fn get_deep_value(&self) -> LoroValue
pub fn get_deep_value(&self) -> LoroValue
Get the deep JSON value of the entire document.
Sourcepub fn commit(&self)
pub fn commit(&self)
Commit pending changes. This triggers the subscribe_local_update
callback, which feeds the sync task.
Sourcepub fn export_snapshot(&self) -> Result<Vec<u8>, CrdtDocError>
pub fn export_snapshot(&self) -> Result<Vec<u8>, CrdtDocError>
Export the document as a full snapshot.
Sourcepub fn export_updates_since(
&self,
vv: &VersionVector,
) -> Result<Vec<u8>, CrdtDocError>
pub fn export_updates_since( &self, vv: &VersionVector, ) -> Result<Vec<u8>, CrdtDocError>
Export incremental updates since the given version vector.
Sourcepub fn import(&self, data: &[u8]) -> Result<(), CrdtDocError>
pub fn import(&self, data: &[u8]) -> Result<(), CrdtDocError>
Import binary data (snapshot or updates) into the document.
Sourcepub fn version_vector(&self) -> VersionVector
pub fn version_vector(&self) -> VersionVector
Get the current version vector of the document.
Sourcepub fn subscribe(&self) -> Receiver<CrdtDocEvent>
pub fn subscribe(&self) -> Receiver<CrdtDocEvent>
Subscribe to document events.
Sourcepub fn compact(&self) -> Result<(), CrdtDocError>
pub fn compact(&self) -> Result<(), CrdtDocError>
Compact the document: export a snapshot and save it to the backend, clearing incremental updates.
Sourcepub fn checkout(&self, frontiers: &Frontiers) -> Result<(), CrdtDocError>
pub fn checkout(&self, frontiers: &Frontiers) -> Result<(), CrdtDocError>
Checkout the document to a specific version (frontiers).
The document becomes “detached” — local edits are not allowed until
checkout_to_latest is called.
Sourcepub fn checkout_to_latest(&self)
pub fn checkout_to_latest(&self)
Return to the latest version after a checkout.
Sourcepub fn is_detached(&self) -> bool
pub fn is_detached(&self) -> bool
Whether the document is in “detached” mode (checked out to a historical version).
Sourcepub fn fork(&self) -> Result<LoroDoc, CrdtDocError>
pub fn fork(&self) -> Result<LoroDoc, CrdtDocError>
Fork the document — create an independent LoroDoc clone.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for CrdtDoc
impl !RefUnwindSafe for CrdtDoc
impl Send for CrdtDoc
impl Sync for CrdtDoc
impl Unpin for CrdtDoc
impl UnsafeUnpin for CrdtDoc
impl !UnwindSafe for CrdtDoc
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
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> 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);