Enum loro_delta::DeltaItem

source ·
pub enum DeltaItem<V, Attr> {
    Retain {
        len: usize,
        attr: Attr,
    },
    Replace {
        value: V,
        attr: Attr,
        delete: usize,
    },
}

Variants§

§

Retain

Fields

§len: usize
§attr: Attr
§

Replace

This is the combined of a delete and an insert.

They are two separate operations in the original Quill Delta format. But the order of two neighboring delete and insert operations can be swapped without changing the result. So Quill requires that the insert always comes before the delete. So it creates room for invalid deltas by the type system. Using Replace is a way to avoid this.

Fields

§value: V
§attr: Attr
§delete: usize

Implementations§

source§

impl<V: DeltaValue, Attr> DeltaItem<V, Attr>

source

pub fn delta_len(&self) -> usize

The real length of the item in the delta

source

pub fn data_len(&self) -> usize

source

pub fn new_insert(value: V, attr: Attr) -> Self

source§

impl<V: DeltaValue, Attr: Default> DeltaItem<V, Attr>

source

pub fn new_delete(len: usize) -> Self

source§

impl<V, Attr> DeltaItem<V, Attr>

source

pub fn as_retain_mut(&mut self) -> Option<(&mut usize, &mut Attr)>

Optionally returns mutable references to the inner fields if this is a DeltaItem::Retain, otherwise None

source

pub fn as_retain(&self) -> Option<(&usize, &Attr)>

Optionally returns references to the inner fields if this is a DeltaItem::Retain, otherwise None

source

pub fn into_retain(self) -> Result<(usize, Attr), Self>

Returns the inner fields if this is a DeltaItem::Retain, otherwise returns back the enum in the Err case of the result

source

pub fn as_replace_mut(&mut self) -> Option<(&mut V, &mut Attr, &mut usize)>

Optionally returns mutable references to the inner fields if this is a DeltaItem::Replace, otherwise None

source

pub fn as_replace(&self) -> Option<(&V, &Attr, &usize)>

Optionally returns references to the inner fields if this is a DeltaItem::Replace, otherwise None

source

pub fn into_replace(self) -> Result<(V, Attr, usize), Self>

Returns the inner fields if this is a DeltaItem::Replace, otherwise returns back the enum in the Err case of the result

Trait Implementations§

source§

impl<V: DeltaValue, Attr: Clone> CanRemove for DeltaItem<V, Attr>

source§

impl<V: Clone, Attr: Clone> Clone for DeltaItem<V, Attr>

source§

fn clone(&self) -> DeltaItem<V, Attr>

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<V: Debug, Attr: Debug> Debug for DeltaItem<V, Attr>

source§

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

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

impl<V: DeltaValue, Attr: DeltaAttr> Default for DeltaItem<V, Attr>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<V: DeltaValue, Attr> HasLength for DeltaItem<V, Attr>

source§

fn rle_len(&self) -> usize

This would treat the len of the Delete as 0

source§

impl<V: Mergeable, Attr: PartialEq> Mergeable for DeltaItem<V, Attr>

source§

fn can_merge(&self, rhs: &Self) -> bool

Whether self can merge rhs with self on the left. Read more
source§

fn merge_right(&mut self, rhs: &Self)

source§

fn merge_left(&mut self, left: &Self)

source§

impl<V: PartialEq, Attr: PartialEq> PartialEq for DeltaItem<V, Attr>

source§

fn eq(&self, other: &DeltaItem<V, Attr>) -> 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<V: DeltaValue, Attr: DeltaAttr> Sliceable for DeltaItem<V, Attr>

source§

fn slice_(&mut self, range: impl RangeBounds<usize>)

slice in-place

source§

fn update_with_split( &mut self, range: impl RangeBounds<usize>, f: impl FnOnce(&mut Self) ) -> (Option<Self>, Option<Self>)

Update the slice in the given range. This method may split self into two or three parts. If so, it will make self the leftmost part and return the next split parts.

§Example

If self.rle_len() == 10, self.update(1..5) will split self into three parts and update the middle part. It returns the middle and the right part.

source§

fn _slice(&self, range: Range<usize>) -> Self

source§

fn split(&mut self, pos: usize) -> Self

source§

fn slice(&self, range: impl RangeBounds<usize>) -> Self

source§

impl<V: DeltaValue, Attr: Clone + PartialEq + Debug> TryInsert for DeltaItem<V, Attr>

source§

fn try_insert(&mut self, pos: usize, elem: Self) -> Result<(), Self>
where Self: Sized,

source§

impl<V: DeltaValue, Attr: DeltaAttr> DeltaValue for DeltaItem<V, Attr>

source§

impl<V: Eq, Attr: Eq> Eq for DeltaItem<V, Attr>

source§

impl<V, Attr> StructuralPartialEq for DeltaItem<V, Attr>

Auto Trait Implementations§

§

impl<V, Attr> Freeze for DeltaItem<V, Attr>
where Attr: Freeze, V: Freeze,

§

impl<V, Attr> RefUnwindSafe for DeltaItem<V, Attr>
where Attr: RefUnwindSafe, V: RefUnwindSafe,

§

impl<V, Attr> Send for DeltaItem<V, Attr>
where Attr: Send, V: Send,

§

impl<V, Attr> Sync for DeltaItem<V, Attr>
where Attr: Sync, V: Sync,

§

impl<V, Attr> Unpin for DeltaItem<V, Attr>
where Attr: Unpin, V: Unpin,

§

impl<V, Attr> UnwindSafe for DeltaItem<V, Attr>
where Attr: UnwindSafe, V: UnwindSafe,

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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, 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.