Struct loro_internal::loro::LoroDoc

source ·
pub struct LoroDoc { /* private fields */ }
Expand description

LoroApp serves as the library’s primary entry point. It’s constituted by an OpLog and an [AppState].

  • OpLog encompasses all operations, signifying the document history.
  • [AppState] signifies the current document state.

They will share a super::arena::SharedArena

Detached Mode

This mode enables separate usage of OpLog and [AppState]. It facilitates temporal navigation. [AppState] can be reverted to any version contained within the OpLog.

LoroApp::detach() separates [AppState] from OpLog. In this mode, updates to OpLog won’t affect [AppState], while updates to [AppState] will continue to affect OpLog.

Implementations§

source§

impl LoroDoc

source

pub fn new() -> Self

source

pub fn new_auto_commit() -> Self

Create a doc with auto commit enabled.

source

pub fn from_snapshot(bytes: &[u8]) -> LoroResult<Self>

source

pub fn can_reset_with_snapshot(&self) -> bool

Is the document empty? (no ops)

source

pub fn is_detached(&self) -> bool

Whether OpLog ans DocState are detached.

source

pub fn peer_id(&self) -> PeerID

source

pub fn set_peer_id(&self, peer: PeerID) -> LoroResult<()>

source

pub fn detach(&mut self)

source

pub fn attach(&mut self)

source

pub fn state_timestamp(&self) -> Timestamp

Get the timestamp of the current state. It’s the last edit time of the DocState.

source

pub fn txn(&self) -> Result<Transaction, LoroError>

Create a new transaction. Every ops created inside one transaction will be packed into a single [Change].

There can only be one active transaction at a time for a LoroDoc.

source

pub fn with_txn<F, R>(&self, f: F) -> LoroResult<R>where F: FnOnce(&mut Transaction) -> LoroResult<R>,

source

pub fn start_auto_commit(&mut self)

source

pub fn commit_then_stop(&self)

Commit the cumulative auto commit transaction. This method only has effect when auto_commit is true.

Afterwards, the users need to call self.renew_txn_after_commit() to resume the continuous transaction.

source

pub fn commit_then_renew(&self)

Commit the cumulative auto commit transaction. It will start the next one immediately

source

pub fn commit_with( &self, origin: Option<DefaultAtom>, timestamp: Option<Timestamp>, immediate_renew: bool )

Commit the cumulative auto commit transaction. This method only has effect when auto_commit is true. If immediate_renew is true, a new transaction will be created after the old one is commited

source

pub fn abort_txn(&self)

Abort the current auto commit transaction.

Afterwards, the users need to call self.renew_txn_after_commit() to resume the continuous transaction.

source

pub fn renew_txn_if_auto_commit(&self)

source

pub fn txn_with_origin(&self, origin: &str) -> Result<Transaction, LoroError>

Create a new transaction with specified origin.

The origin will be propagated to the events. There can only be one active transaction at a time for a LoroDoc.

source

pub fn app_state(&self) -> &Arc<Mutex<DocState>>

source

pub fn get_state_deep_value(&self) -> LoroValue

source

pub fn oplog(&self) -> &Arc<Mutex<OpLog>>

source

pub fn export_from(&self, vv: &VersionVector) -> Vec<u8>

source

pub fn import(&self, bytes: &[u8]) -> Result<(), LoroError>

source

pub fn import_without_state(&mut self, bytes: &[u8]) -> Result<(), LoroError>

source

pub fn import_with( &self, bytes: &[u8], origin: DefaultAtom ) -> Result<(), LoroError>

source

pub fn export_snapshot(&self) -> Vec<u8>

source

pub fn oplog_vv(&self) -> VersionVector

Get the version vector of the current OpLog

source

pub fn state_vv(&self) -> VersionVector

Get the version vector of the current DocState

source

pub fn get_text<I: IntoContainerId>(&self, id: I) -> TextHandler

id can be a str, ContainerID, or ContainerIdRaw. if it’s str it will use Root container, which will not be None

source

pub fn get_list<I: IntoContainerId>(&self, id: I) -> ListHandler

id can be a str, ContainerID, or ContainerIdRaw. if it’s str it will use Root container, which will not be None

source

pub fn get_map<I: IntoContainerId>(&self, id: I) -> MapHandler

id can be a str, ContainerID, or ContainerIdRaw. if it’s str it will use Root container, which will not be None

source

pub fn get_tree<I: IntoContainerId>(&self, id: I) -> TreeHandler

id can be a str, ContainerID, or ContainerIdRaw. if it’s str it will use Root container, which will not be None

source

pub fn diagnose_size(&self)

This is for debugging purpose. It will travel the whole oplog

source

pub fn oplog_frontiers(&self) -> Frontiers

source

pub fn state_frontiers(&self) -> Frontiers

source

pub fn cmp_frontiers(&self, other: &Frontiers) -> Ordering

  • Ordering::Less means self is less than target or parallel
  • Ordering::Equal means versions equal
  • Ordering::Greater means self’s version is greater than target
source

pub fn subscribe_root(&self, callback: Subscriber) -> SubID

source

pub fn subscribe( &self, container_id: &ContainerID, callback: Subscriber ) -> SubID

source

pub fn unsubscribe(&self, id: SubID)

source

pub fn import_batch(&mut self, bytes: &[Vec<u8>]) -> LoroResult<()>

source

pub fn get_deep_value(&self) -> LoroValue

Get deep value of the document.

source

pub fn get_deep_value_with_id(&self) -> LoroValue

Get deep value of the document with container id

source

pub fn checkout_to_latest(&mut self)

source

pub fn checkout(&mut self, frontiers: &Frontiers) -> LoroResult<()>

Checkout DocState to a specific version.

This will make the current DocState detached from the latest version of OpLog. Any further import will not be reflected on the DocState, until user call LoroDoc::attach()

source

pub fn vv_to_frontiers(&self, vv: &VersionVector) -> Frontiers

source

pub fn frontiers_to_vv(&self, frontiers: &Frontiers) -> Option<VersionVector>

source

pub fn merge(&self, other: &Self) -> LoroResult<()>

Import ops from other doc.

After a.merge(b) and b.merge(a), a and b will have the same content if they are in attached mode.

Trait Implementations§

source§

impl Default for LoroDoc

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> ZeroElement for Twhere T: Default,