Struct yrs::types::text::Text [−][src]
pub struct Text(_);
Expand description
A shared data type used for collaborative text editing. It enables multiple users to add and remove chunks of text in efficient manner. This type is internally represented as a mutable double-linked list of text chunks - an optimization occurs during Transaction::commit, which allows to squash multiple consecutively inserted characters together as a single chunk of text even between transaction boundaries in order to preserve more efficient memory model.
Text structure internally uses UTF-8 encoding and its length is described in a number of bytes rather than individual characters (a single UTF-8 code point can consist of many bytes).
Like all Yrs shared data types, Text is resistant to the problem of interleaving (situation when characters inserted one after another may interleave with other peers concurrent inserts after merging all updates together). In case of Yrs conflict resolution is solved by using unique document id to determine correct and consistent ordering.
Implementations
Converts context of this text data structure into a single string value.
Returns a number of characters visible in a current text data structure.
Inserts a chunk
of text at a given index
.
If index
is 0
, this chunk
will be inserted at the beginning of a current text.
If index
is equal to current data structure length, this chunk
will be appended at
the end of it.
This method will panic if provided index
is greater than the length of a current text.
Appends a given chunk
of text at the end of a current text structure.
Removes up to a len
characters from a current text structure, starting at given index
.
This method panics in case when not all expected characters were removed (due to
insufficient number of characters to remove) or index
is outside of the bounds of text.
Subscribes a given callback to be triggered whenever current text is changed. A callback is triggered whenever a transaction gets committed. This function does not trigger if changes have been observed by nested shared collections.
All text changes can be tracked by using Event::delta method: keep in mind that delta contains collection of individual characters rather than strings.
Returns an Observer which, when dropped, will unsubscribe current callback.
Trait Implementations
Performs the conversion.
Auto Trait Implementations
impl !RefUnwindSafe for Text
impl !UnwindSafe for Text
Blanket Implementations
Mutably borrows from an owned value. Read more