Enum yrs::block::ItemContent

source ·
pub enum ItemContent {
    Any(Vec<Any>),
    Binary(Vec<u8>),
    Deleted(u32),
    Doc(Option<Doc>, Doc),
    JSON(Vec<String>),
    Embed(Any),
    Format(Arc<str>, Box<Any>),
    String(SplittableString),
    Type(Arc<Branch>),
    Move(Box<Move>),
}
Expand description

An enum describing the type of a user data content stored as part of one or more (if items were squashed) insert operations.

Variants§

§

Any(Vec<Any>)

Collection of consecutively inserted JSON-like primitive values.

§

Binary(Vec<u8>)

A BLOB data eg. images. Binaries are treated as a single objects (they are not subjects to splits).

§

Deleted(u32)

A marker for delete item data, which describes a number of deleted elements. Deleted elements also don’t contribute to an overall length of containing collection type.

§

Doc(Option<Doc>, Doc)

Sub-document container. Contains weak reference to a parent document and a child document.

§

JSON(Vec<String>)

Obsolete: collection of consecutively inserted stringified JSON values.

§

Embed(Any)

A single embedded JSON-like primitive value.

§

Format(Arc<str>, Box<Any>)

Formatting attribute entry. Format attributes are not considered countable and don’t contribute to an overall length of a collection they are applied to.

§

String(SplittableString)

A chunk of text, usually applied by collaborative text insertion.

§

Type(Arc<Branch>)

A reference of a branch node. Branch nodes define a complex collection types, such as arrays, maps or XML elements.

§

Move(Box<Move>)

Marker for destination location of move operation. Move is used to change position of previously inserted element in a sequence with respect to other operations that may happen concurrently on other peers.

Implementations§

source§

impl ItemContent

source

pub fn get_ref_number(&self) -> u8

Returns a reference number used to determine a content type. It’s used during encoding/decoding of a containing block.

source

pub fn is_countable(&self) -> bool

Checks if item content can be considered countable. Countable elements contribute to a length of the block they are contained by. Most of the item content variants are countable with exception for ItemContent::Deleted (which length describes number of removed elements) and ItemContent::Format (which is used for storing text formatting tags).

source

pub fn len(&self, kind: OffsetKind) -> u32

Returns a number of separate elements contained within current item content struct.

Separate elements can be split in order to put another block in between them. Definition of separation depends on a item content kin, eg. ItemContent::String, ItemContent::Any, ItemContent::JSON and ItemContent::Deleted can have variable length as they may be split by other insert operations. Other variants (eg. ItemContent::Binary) are considered as a single element and therefore their length is always 1 and are not considered as subject of splitting.

In cases of counting number of visible elements, len method should be used together with ItemContent::is_countable.

source

pub fn read(&self, offset: usize, buf: &mut [Value]) -> usize

Reads a contents of current ItemContent into a given buf, starting from provided offset. Returns a number of elements read this way (it cannot be longer than buf’s len.

source

pub fn get_content(&self) -> Vec<Value>

Reads all contents stored in this item and returns them. Use ItemContent::read if you need to read only slice of elements from the corresponding item.

source

pub fn get_first(&self) -> Option<Value>

Returns a first value stored in a corresponding item.

source

pub fn get_last(&self) -> Option<Value>

Returns a last value stored in a corresponding item.

source

pub fn encode_slice<E: Encoder>(&self, encoder: &mut E, start: u32, end: u32)

Encodes a slice of a current ItemContent within an index bounds of (start..=end) - both sides inclusive.

source

pub fn encode<E: Encoder>(&self, encoder: &mut E)

source

pub fn decode<D: Decoder>(decoder: &mut D, ref_num: u8) -> Result<Self, Error>

source

pub fn try_squash(&mut self, other: &Self) -> bool

Tries to squash two item content structures together. Returns true if this method had any effect on current ItemContent (modified it). Otherwise returns false.

Trait Implementations§

source§

impl Clone for ItemContent

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ItemContent

source§

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

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

impl Display for ItemContent

source§

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

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

impl PartialEq for ItemContent

source§

fn eq(&self, other: &ItemContent) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for ItemContent

Auto Trait Implementations§

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, 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.