Skip to main content

Transaction

Struct Transaction 

Source
pub struct Transaction<'doc> { /* private fields */ }
Expand description

A very lightweight read-only transaction. These transactions are guaranteed to not modify the contents of an underlying Doc and can be used to read it or for serialization purposes. For this reason it’s allowed to have a multiple active read-only transactions, but it’s not allowed to have any active read-write transactions at the same time.

Trait Implementations§

Source§

impl<'doc> Debug for Transaction<'doc>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'doc> ReadTxn for Transaction<'doc>

Source§

fn store(&self) -> &Store

Source§

fn state_vector(&self) -> StateVector

Returns state vector describing current state of the updates.
Source§

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,

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,

Encodes the difference between remote peer state given its state_vector and the state of a current local peer. Read more
Source§

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 more
Source§

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 more
Source§

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 more
Source§

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 more
Source§

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 more
Source§

fn root_refs(&self) -> RootRefs<'_>

Returns an iterator over top level (root) shared types available in current Doc.
Source§

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<'_>

Returns a collection of sub documents linked within the structures of this document store.
Source§

fn get_text<N>(&self, name: N) -> Option<TextRef>
where N: Into<Arc<str>>,

Returns a TextRef 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. Read more
Source§

fn get_array<N>(&self, name: N) -> Option<ArrayRef>
where N: Into<Arc<str>>,

Returns an ArrayRef 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. Read more
Source§

fn get_map<N>(&self, name: N) -> Option<MapRef>
where N: Into<Arc<str>>,

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 more
Source§

fn get_xml_fragment<N>(&self, name: N) -> Option<XmlFragmentRef>
where N: Into<Arc<str>>,

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 more
Source§

fn get<S>(&self, name: S) -> Option<Out>
where S: AsRef<str>,

Source§

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>

If current document has been inserted as a sub-document, returns its BranchID.
Source§

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<'doc> Freeze for Transaction<'doc>

§

impl<'doc> !RefUnwindSafe for Transaction<'doc>

§

impl<'doc> !Send for Transaction<'doc>

§

impl<'doc> !Sync for Transaction<'doc>

§

impl<'doc> Unpin for Transaction<'doc>

§

impl<'doc> !UnwindSafe for Transaction<'doc>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> JsonPathEval for T
where T: ReadTxn,

Source§

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"))]);
Source§

type Iter<'a> = JsonPathIter<'a, T> where T: 'a

Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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