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
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 read(&self, offset: usize, buf: &mut [Out]) -> usize
pub fn read(&self, offset: usize, buf: &mut [Out]) -> 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.
sourcepub fn get_content(&self) -> Vec<Out>
pub fn get_content(&self) -> Vec<Out>
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.
sourcepub fn encode_slice<E: Encoder>(&self, encoder: &mut E, start: u32, end: u32)
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.
pub fn encode<E: Encoder>(&self, encoder: &mut E)
pub fn decode<D: Decoder>(decoder: &mut D, ref_num: u8) -> Result<Self, Error>
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.
Returns true
if this method had any effect on current ItemContent (modified it).
Otherwise returns false
.
Trait Implementations§
source§impl Clone for ItemContent
impl Clone for ItemContent
source§impl Debug for ItemContent
impl Debug for ItemContent
source§impl Display for ItemContent
impl Display for ItemContent
source§impl PartialEq for ItemContent
impl PartialEq for ItemContent
impl StructuralPartialEq for ItemContent
Auto Trait Implementations§
impl Freeze for ItemContent
impl !RefUnwindSafe for ItemContent
impl !Send for ItemContent
impl !Sync for ItemContent
impl Unpin for ItemContent
impl !UnwindSafe for ItemContent
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)