Struct yrs::Transaction
source · [−]pub struct Transaction {
pub before_state: StateVector,
pub after_state: StateVector,
pub delete_set: DeleteSet,
/* private fields */
}
Expand description
Transaction is one of the core types in Yrs. All operations that need to touch a document’s contents (a.k.a. block store), need to be executed in scope of a transaction.
Fields
before_state: StateVector
State vector of a current transaction at the moment of its creation.
after_state: StateVector
Current state vector of a transaction, which includes all performed updates.
delete_set: DeleteSet
Describes the set of deleted items by ids.
Implementations
sourceimpl Transaction
impl Transaction
sourcepub fn state_vector(&self) -> StateVector
pub fn state_vector(&self) -> StateVector
Returns state vector describing current state of the updates.
pub fn snapshot(&self) -> Snapshot
sourcepub fn encode_diff<E: Encoder>(
&self,
state_vector: &StateVector,
encoder: &mut E
)
pub fn encode_diff<E: Encoder>(
&self,
state_vector: &StateVector,
encoder: &mut E
)
Encodes the difference between remove peer state given its state_vector
and the state
of a current local peer
pub fn encode_diff_v1(&self, state_vector: &StateVector) -> Vec<u8>
sourcepub fn get_text(&mut self, name: &str) -> Text
pub fn get_text(&mut self, name: &str) -> Text
Returns a Text data structure stored under a given name
. Text structures are used for
collaborative text editing: they expose operations to append and remove chunks of text,
which are free to execute concurrently by multiple peers over remote boundaries.
If not structure under defined name
existed before, it will be created and returned
instead.
If a structure under defined name
already existed, but its type was different it will be
reinterpreted as a text (in such case a sequence component of complex data type will be
interpreted as a list of text chunks).
sourcepub fn get_map(&mut self, name: &str) -> Map
pub fn get_map(&mut self, name: &str) -> Map
Returns a Map data structure stored under a given name
. Maps are used to store key-value
pairs associated together. 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.
If not structure under defined name
existed before, it will be created and returned
instead.
If a structure under defined name
already existed, but its type was different it will be
reinterpreted as a map (in such case a map component of complex data type will be
interpreted as native map).
sourcepub fn get_array(&mut self, name: &str) -> Array
pub fn get_array(&mut self, name: &str) -> Array
Returns an Array data structure stored under a given name
. Array structures are used for
storing a sequences of elements in ordered manner, positioning given element accordingly
to its index.
If not structure under defined name
existed before, it will be created and returned
instead.
If a structure under defined name
already existed, but its type was different it will be
reinterpreted as an array (in such case a sequence component of complex data type will be
interpreted as a list of inserted values).
sourcepub fn get_xml_element(&mut self, name: &str) -> XmlElement
pub fn get_xml_element(&mut self, name: &str) -> XmlElement
Returns a XmlElement 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)
as well as other nested XML elements or text values, which are stored in their insertion
order.
If not structure under defined name
existed before, it will be created and returned
instead.
If a structure under defined name
already existed, but its type was different it will be
reinterpreted as a XML element (in such case a map component of complex data type will be
interpreted as map of its attributes, while a sequence component - as a list of its child
XML nodes).
sourcepub fn get_xml_text(&mut self, name: &str) -> XmlText
pub fn get_xml_text(&mut self, name: &str) -> XmlText
Returns a XmlText data structure stored under a given name
. Text structures are used for
collaborative text editing: they expose operations to append and remove chunks of text,
which are free to execute concurrently by multiple peers over remote boundaries.
If not structure under defined name
existed before, it will be created and returned
instead.
If a structure under defined name
already existed, but its type was different it will be
reinterpreted as a text (in such case a sequence component of complex data type will be
interpreted as a list of text chunks).
sourcepub fn encode_update_v1(&self) -> Vec<u8>
pub fn encode_update_v1(&self) -> Vec<u8>
Encodes the document state to a binary format.
Document updates are idempotent and commutative. Caveats:
- It doesn’t matter in which order document updates are applied.
- As long as all clients receive the same document updates, all clients end up with the same content.
- Even if an update contains known information, the unknown information is extracted and integrated into the document structure.
sourcepub fn encode_update<E: Encoder>(&self, encoder: &mut E)
pub fn encode_update<E: Encoder>(&self, encoder: &mut E)
Encodes the document state to a binary format.
Document updates are idempotent and commutative. Caveats:
- It doesn’t matter in which order document updates are applied.
- As long as all clients receive the same document updates, all clients end up with the same content.
- Even if an update contains known information, the unknown information is extracted and integrated into the document structure.
sourcepub fn encode_update_v2(&self) -> Vec<u8>
pub fn encode_update_v2(&self) -> Vec<u8>
Encodes the document state to a binary format.
Document updates are idempotent and commutative. Caveats:
- It doesn’t matter in which order document updates are applied.
- As long as all clients receive the same document updates, all clients end up with the same content.
- Even if an update contains known information, the unknown information is extracted and integrated into the document structure.
sourcepub fn apply_update(&mut self, update: Update)
pub fn apply_update(&mut self, update: Update)
Applies a deserialized update contents into a document owning current transaction.
sourcepub fn commit(&mut self)
pub fn commit(&mut self)
Commits current transaction. This step involves cleaning up and optimizing changes performed during lifetime of a transaction. Such changes include squashing delete sets data or squashing blocks that have been appended one after another to preserve memory.
This step is performed automatically when a transaction is about to be dropped (its life scope comes to an end).
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Transaction
impl !Send for Transaction
impl !Sync for Transaction
impl Unpin for Transaction
impl !UnwindSafe for Transaction
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more