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 set_record_timestamp(&self, record: bool)
pub fn set_record_timestamp(&self, record: bool)
Set whether to record the timestamp of each change. Default is false
.
If enabled, the Unix timestamp will be recorded for each change automatically.
You can also set each timestamp manually when you commit a change. The timstamp manually set will override the automatic one.
NOTE: Timestamps are forced to be in ascending order. If you commit a new change with a timestamp that is less than the existing one, the largest existing timestamp will be used instead.
sourcepub fn set_change_merge_interval(&self, interval: i64)
pub fn set_change_merge_interval(&self, interval: i64)
Set the interval of mergeable changes.
If two continuous local changes are within the interval, they will be merged into one change. The defualt value is 1000 seconds.
pub fn config_text_style(&self, text_style: StyleConfigMap)
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(&self)
pub fn attach(&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>
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<InternalString>,
timestamp: Option<Timestamp>,
immediate_renew: bool
)
pub fn commit_with( &self, origin: Option<InternalString>, 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 committed
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_with( &self, bytes: &[u8], origin: InternalString ) -> 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
pub fn get_by_path(&self, path: &[Index]) -> Option<ValueOrHandler>
sourcepub fn get_by_str_path(&self, path: &str) -> Option<ValueOrHandler>
pub fn get_by_str_path(&self, path: &str) -> Option<ValueOrHandler>
Get the handler by the string path.
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_with_frontiers(&self, other: &Frontiers) -> Ordering
pub fn cmp_with_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
sourcepub fn cmp_frontiers(
&self,
a: &Frontiers,
b: &Frontiers
) -> Result<Option<Ordering>, FrontiersNotIncluded>
pub fn cmp_frontiers( &self, a: &Frontiers, b: &Frontiers ) -> Result<Option<Ordering>, FrontiersNotIncluded>
Compare two Frontiers causally.
If one of the Frontiers are not included, it will return FrontiersNotIncluded.
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(&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(&self)
sourcepub fn checkout(&self, frontiers: &Frontiers) -> LoroResult<()>
pub fn checkout(&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.
pub fn len_ops(&self) -> usize
pub fn len_changes(&self) -> usize
pub fn config(&self) -> &Configure
sourcepub fn check_state_diff_calc_consistency_slow(&self)
pub fn check_state_diff_calc_consistency_slow(&self)
This method compare the consistency between the current doc state and the state calculated by diff calculator from beginning.
Panic when it’s not consistent
pub fn log_estimated_size(&self)
sourcepub fn query_pos(
&self,
pos: &Cursor
) -> Result<PosQueryResult, CannotFindRelativePosition>
pub fn query_pos( &self, pos: &Cursor ) -> Result<PosQueryResult, CannotFindRelativePosition>
Get position in a seq container
source§impl LoroDoc
impl LoroDoc
sourcepub fn decode_import_blob_meta(blob: &[u8]) -> LoroResult<ImportBlobMetadata>
pub fn decode_import_blob_meta(blob: &[u8]) -> LoroResult<ImportBlobMetadata>
Decodes the metadata for an imported blob from the provided bytes.