Enum yrs::block::ItemContent
source · [−]pub enum ItemContent {
Any(Vec<Any>),
Binary(Vec<u8>),
Deleted(u32),
Doc(Box<str>, Box<Any>),
JSON(Vec<String>),
Embed(Box<Any>),
Format(Rc<str>, Box<Any>),
String(SplittableString),
Type(Box<Branch>),
}
Expand description
An enum describing the type of a user content stored as part of one or more (if items were squashed) insert operations.
Variants
Any(Vec<Any>)
Any JSON-like primitive type range.
Binary(Vec<u8>)
A binary data eg. images.
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(Box<str>, Box<Any>)
JSON(Vec<String>)
Embed(Box<Any>)
Format(Rc<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(Box<Branch>)
A reference of a branch node. Branch nodes define a complex collection types, such as arrays, maps or XML elements.
Implementations
sourceimpl ItemContent
impl ItemContent
sourcepub fn get_ref_number(&self) -> u8
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.
sourcepub fn is_countable(&self) -> bool
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).
sourcepub fn len(&self, kind: OffsetKind) -> u32
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.
sourcepub fn get_content(&self) -> Vec<Value>
pub fn get_content(&self) -> Vec<Value>
Returns a formatted content of an item. For complex types (represented by [BranchRef] nodes) it will return a target type of a branch node (eg. Yrs Array, Map or XmlElement). For other types it will returns a vector of elements stored within current block. Since block may describe a chunk of values within it, it always returns a vector of values.
sourcepub fn get_content_last(&self) -> Option<Value>
pub fn get_content_last(&self) -> Option<Value>
Similar to [get_content], but it only returns the latest result and doesn’t materialize others for performance reasons.
pub fn encode_with_offset<E: Encoder>(&self, encoder: &mut E, offset: u32)
pub fn encode<E: Encoder>(&self, encoder: &mut E)
pub fn decode<D: Decoder>(decoder: &mut D, ref_num: u8) -> Self
sourcepub fn try_squash(&mut self, other: &Self) -> bool
pub fn try_squash(&mut self, other: &Self) -> bool
Tries to squash two item content structures together.
Trait Implementations
sourceimpl Debug for ItemContent
impl Debug for ItemContent
sourceimpl Display for ItemContent
impl Display for ItemContent
sourceimpl PartialEq<ItemContent> for ItemContent
impl PartialEq<ItemContent> for ItemContent
sourcefn eq(&self, other: &ItemContent) -> bool
fn eq(&self, other: &ItemContent) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &ItemContent) -> bool
fn ne(&self, other: &ItemContent) -> bool
This method tests for !=
.
impl StructuralPartialEq for ItemContent
Auto Trait Implementations
impl !RefUnwindSafe for ItemContent
impl !Send for ItemContent
impl !Sync for ItemContent
impl Unpin for ItemContent
impl !UnwindSafe for ItemContent
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