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
impl LoroDoc
pub fn new() -> Self
sourcepub fn new_auto_commit() -> Self
pub fn new_auto_commit() -> Self
Create a doc with auto commit enabled.
pub fn from_snapshot(bytes: &[u8]) -> LoroResult<Self>
sourcepub fn can_reset_with_snapshot(&self) -> bool
pub fn can_reset_with_snapshot(&self) -> bool
Is the document empty? (no ops)
sourcepub fn is_detached(&self) -> bool
pub fn is_detached(&self) -> bool
pub fn peer_id(&self) -> PeerID
pub fn set_peer_id(&self, peer: PeerID) -> LoroResult<()>
pub fn detach(&mut self)
pub fn attach(&mut self)
sourcepub fn state_timestamp(&self) -> Timestamp
pub fn state_timestamp(&self) -> Timestamp
Get the timestamp of the current state. It’s the last edit time of the DocState.
sourcepub fn txn(&self) -> Result<Transaction, LoroError>
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.
pub fn with_txn<F, R>(&self, f: F) -> LoroResult<R>where F: FnOnce(&mut Transaction) -> LoroResult<R>,
pub fn start_auto_commit(&mut self)
sourcepub fn commit_then_stop(&self)
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.
sourcepub fn commit_then_renew(&self)
pub fn commit_then_renew(&self)
Commit the cumulative auto commit transaction. It will start the next one immediately
sourcepub fn commit_with(
&self,
origin: Option<DefaultAtom>,
timestamp: Option<Timestamp>,
immediate_renew: bool
)
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
sourcepub fn abort_txn(&self)
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.
pub fn renew_txn_if_auto_commit(&self)
sourcepub fn txn_with_origin(&self, origin: &str) -> Result<Transaction, LoroError>
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.
pub fn app_state(&self) -> &Arc<Mutex<DocState>>
pub fn get_state_deep_value(&self) -> LoroValue
pub fn oplog(&self) -> &Arc<Mutex<OpLog>>
pub fn export_from(&self, vv: &VersionVector) -> Vec<u8> ⓘ
pub fn import(&self, bytes: &[u8]) -> Result<(), LoroError>
pub fn import_without_state(&mut self, bytes: &[u8]) -> Result<(), LoroError>
pub fn import_with( &self, bytes: &[u8], origin: DefaultAtom ) -> Result<(), LoroError>
pub fn export_snapshot(&self) -> Vec<u8> ⓘ
sourcepub fn oplog_vv(&self) -> VersionVector
pub fn oplog_vv(&self) -> VersionVector
Get the version vector of the current OpLog
sourcepub fn state_vv(&self) -> VersionVector
pub fn state_vv(&self) -> VersionVector
Get the version vector of the current DocState
sourcepub fn get_text<I: IntoContainerId>(&self, id: I) -> TextHandler
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
sourcepub fn get_list<I: IntoContainerId>(&self, id: I) -> ListHandler
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
sourcepub fn get_map<I: IntoContainerId>(&self, id: I) -> MapHandler
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
sourcepub fn get_tree<I: IntoContainerId>(&self, id: I) -> TreeHandler
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
sourcepub fn diagnose_size(&self)
pub fn diagnose_size(&self)
This is for debugging purpose. It will travel the whole oplog
pub fn oplog_frontiers(&self) -> Frontiers
pub fn state_frontiers(&self) -> Frontiers
sourcepub fn cmp_frontiers(&self, other: &Frontiers) -> Ordering
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
pub fn subscribe_root(&self, callback: Subscriber) -> SubID
pub fn subscribe( &self, container_id: &ContainerID, callback: Subscriber ) -> SubID
pub fn unsubscribe(&self, id: SubID)
pub fn import_batch(&mut self, bytes: &[Vec<u8>]) -> LoroResult<()>
sourcepub fn get_deep_value(&self) -> LoroValue
pub fn get_deep_value(&self) -> LoroValue
Get deep value of the document.
sourcepub fn get_deep_value_with_id(&self) -> LoroValue
pub fn get_deep_value_with_id(&self) -> LoroValue
Get deep value of the document with container id
pub fn checkout_to_latest(&mut self)
sourcepub fn checkout(&mut self, frontiers: &Frontiers) -> LoroResult<()>
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()
pub fn vv_to_frontiers(&self, vv: &VersionVector) -> Frontiers
pub fn frontiers_to_vv(&self, frontiers: &Frontiers) -> Option<VersionVector>
sourcepub fn merge(&self, other: &Self) -> LoroResult<()>
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.