pub struct Transaction(/* private fields */);
Expand description
Transaction is one of the core types in Yrs. All operations that need to touch or modify a document’s contents (a.k.a. block store), need to be executed in scope of a transaction.
Trait Implementations§
Source§impl ReadTxn for Transaction
impl ReadTxn for Transaction
fn store(&self) -> &Store
Source§fn state_vector(&self) -> StateVector
fn state_vector(&self) -> StateVector
Returns state vector describing current state of the updates.
Source§fn snapshot(&self) -> Snapshot
fn snapshot(&self) -> Snapshot
Returns a snapshot which describes a current state of updates and removals made within
the corresponding document.
Source§fn encode_state_from_snapshot<E>(
&self,
snapshot: &Snapshot,
encoder: &mut E,
) -> Result<(), Error>where
E: Encoder,
fn encode_state_from_snapshot<E>(
&self,
snapshot: &Snapshot,
encoder: &mut E,
) -> Result<(), Error>where
E: Encoder,
Encodes all changes from current transaction block store up to a given
snapshot
.
This enables to encode state of a document at some specific point in the past.Source§fn encode_diff<E>(&self, state_vector: &StateVector, encoder: &mut E)where
E: Encoder,
fn encode_diff<E>(&self, state_vector: &StateVector, encoder: &mut E)where
E: Encoder,
Encodes the difference between remote peer state given its
state_vector
and the state
of a current local peer. Read moreSource§fn encode_diff_v1(&self, state_vector: &StateVector) -> Vec<u8> ⓘ
fn encode_diff_v1(&self, state_vector: &StateVector) -> Vec<u8> ⓘ
Encodes the difference between remote peer state given its
state_vector
and the state
of a current local peer, using lib0 v1 encoding. Read moreSource§fn encode_diff_v2(&self, state_vector: &StateVector) -> Vec<u8> ⓘ
fn encode_diff_v2(&self, state_vector: &StateVector) -> Vec<u8> ⓘ
Encodes the difference between remote peer state given its
state_vector
and the state
of a current local peer, using lib0 v2 encoding. Read moreSource§fn encode_state_as_update<E>(&self, sv: &StateVector, encoder: &mut E)where
E: Encoder,
fn encode_state_as_update<E>(&self, sv: &StateVector, encoder: &mut E)where
E: Encoder,
Encodes the difference between remote peer state given its
state_vector
and the state
of a current local peer. Also includes pending updates which were not yet integrated into
the main document state and entire delete set. Read moreSource§fn encode_state_as_update_v1(&self, sv: &StateVector) -> Vec<u8> ⓘ
fn encode_state_as_update_v1(&self, sv: &StateVector) -> Vec<u8> ⓘ
Encodes the difference between remote peer state given its
state_vector
and the state
of a current local peer, using lib0 v1 encoding. Also includes pending updates which were
not yet integrated into the main document state and entire delete set. Read moreSource§fn encode_state_as_update_v2(&self, sv: &StateVector) -> Vec<u8> ⓘ
fn encode_state_as_update_v2(&self, sv: &StateVector) -> Vec<u8> ⓘ
Encodes the difference between remote peer state given its
state_vector
and the state
of a current local peer, using lib0 v2 encoding. Also includes pending updates which were
not yet integrated into the main document state and entire delete set. Read moreSource§fn root_refs(&self) -> RootRefs<'_>
fn root_refs(&self) -> RootRefs<'_>
Returns an iterator over top level (root) shared types available in current Doc.
Source§fn subdoc_guids(&self) -> SubdocGuids<'_>
fn subdoc_guids(&self) -> SubdocGuids<'_>
Returns a collection of globally unique identifiers of sub documents linked within
the structures of this document store.
Source§fn subdocs(&self) -> SubdocsIter<'_>
fn subdocs(&self) -> SubdocsIter<'_>
Returns a collection of sub documents linked within the structures of this document store.
Source§fn get_map<N>(&self, name: N) -> Option<MapRef>
fn get_map<N>(&self, name: N) -> Option<MapRef>
Returns a MapRef data structure stored under a given
name
. Maps are used to store key-value
pairs associated. These values can be primitive data (similar but not limited to
a JavaScript Object Notation) as well as other shared types (Yrs maps, arrays, text
structures etc.), enabling to construct a complex recursive tree structures. Read moreSource§fn get_xml_fragment<N>(&self, name: N) -> Option<XmlFragmentRef>
fn get_xml_fragment<N>(&self, name: N) -> Option<XmlFragmentRef>
Returns a XmlFragmentRef data structure stored under a given
name
. XML elements represent
nodes of XML document. They can contain attributes (key-value pairs, both of string type)
and other nested XML elements or text values, which are stored in their insertion
order. Read morefn get<S>(&self, name: S) -> Option<Out>
Source§fn parent_doc(&self) -> Option<Doc>
fn parent_doc(&self) -> Option<Doc>
If current document has been inserted as a sub-document, returns a reference to a parent
document, which contains it.
Source§fn branch_id(&self) -> Option<BranchID>
fn branch_id(&self) -> Option<BranchID>
If current document has been inserted as a sub-document, returns its BranchID.
Source§fn has_missing_updates(&self) -> bool
fn has_missing_updates(&self) -> bool
Returns
true
if current document has any pending updates that are not yet
integrated into the document.Auto Trait Implementations§
impl Freeze for Transaction
impl !RefUnwindSafe for Transaction
impl !Send for Transaction
impl !Sync for Transaction
impl Unpin for Transaction
impl !UnwindSafe for Transaction
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
Mutably borrows from an owned value. Read more
Source§impl<T> JsonPathEval for Twhere
T: ReadTxn,
impl<T> JsonPathEval for Twhere
T: ReadTxn,
Source§fn json_path<'a>(
&'a self,
path: &'a JsonPath<'a>,
) -> <T as JsonPathEval>::Iter<'a>
fn json_path<'a>( &'a self, path: &'a JsonPath<'a>, ) -> <T as JsonPathEval>::Iter<'a>
Evaluate JSON path on the current transaction, starting from current transaction [Doc] as its root.
§Example
use yrs::{any, Array, ArrayPrelim, Doc, In, JsonPath, JsonPathEval, Map, MapPrelim, Out, Transact, WriteTxn};
let doc = Doc::new();
let mut txn = doc.transact_mut();
let users = txn.get_or_insert_array("users");
// populate the document with some data to query
users.insert(&mut txn, 0, MapPrelim::from([
("name".to_string(), In::Any(any!("Alice"))),
("surname".into(), In::Any(any!("Smith"))),
("age".into(), In::Any(any!(25))),
(
"friends".into(),
In::from(ArrayPrelim::from([
any!({ "name": "Bob", "nick": "boreas" }),
any!({ "nick": "crocodile91" }),
])),
),
]));
let query = JsonPath::parse("$.users..friends.*.nick").unwrap();
let values: Vec<Out> = txn.json_path(&query).collect();
assert_eq!(values, vec![Out::Any(any!("boreas")), Out::Any(any!("crocodile91"))]);