Struct fractional_index::zeno_index::ZenoIndex
source · pub struct ZenoIndex(/* private fields */);
👎Deprecated since 2.0.0: Use FractionalIndex instead
Expand description
A ZenoIndex
is a binary representation of a fraction between 0 and 1,
exclusive, with arbitrary precision.
The only operations it supports are:
- Construction of a
ZenoIndex
representing one half. - Comparison of two
ZenoIndex
values. - Returning an arbitrary
ZenoIndex
less or greater than another givenZenoIndex
. - Returning an arbitrary
ZenoIndex
strictly between two otherZenoIndex
es.
Note that as a result of these restrictions:
- It’s possible to arrive at a value infinitely close, but not equal to, zero or one (hence the name).
- We only ever care about the relative value of two
ZenoIndex
es; not their actual value. In fact, the only reason to think about them as fractions at all is because it makes them easier to reason about.
The use of fractional indexes for real-time editing of lists is described in this post. The specifics of the encoding used in that post differ from the one we use.
The underlying data structure used by a ZenoIndex is a vector of bytes. The fraction represented by a given vector of N bytes, where zi is the ith byte (1-based indexing):
(128/256)N + Σi=1..N (zi / 256i)
Implementations§
source§impl ZenoIndex
impl ZenoIndex
sourcepub fn from_bytes(bytes: Vec<u8>) -> Self
👎Deprecated since 2.0.0: Use FractionalIndex instead
pub fn from_bytes(bytes: Vec<u8>) -> Self
Construct a ZenoIndex
from the given byte representation.
sourcepub fn as_bytes(&self) -> &[u8] ⓘ
👎Deprecated since 2.0.0: Use FractionalIndex instead
pub fn as_bytes(&self) -> &[u8] ⓘ
Return a ZenoIndex
’s byte representation.
sourcepub fn new_before(fs: &ZenoIndex) -> ZenoIndex
👎Deprecated since 2.0.0: Use FractionalIndex instead
pub fn new_before(fs: &ZenoIndex) -> ZenoIndex
Construct a new ZenoIndex
that compares as less than the given value.
Trait Implementations§
source§impl<'de> Deserialize<'de> for ZenoIndex
impl<'de> Deserialize<'de> for ZenoIndex
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for ZenoIndex
impl Ord for ZenoIndex
source§impl PartialEq for ZenoIndex
impl PartialEq for ZenoIndex
source§impl PartialOrd for ZenoIndex
impl PartialOrd for ZenoIndex
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Eq for ZenoIndex
impl StructuralEq for ZenoIndex
impl StructuralPartialEq for ZenoIndex
Auto Trait Implementations§
impl RefUnwindSafe for ZenoIndex
impl Send for ZenoIndex
impl Sync for ZenoIndex
impl Unpin for ZenoIndex
impl UnwindSafe for ZenoIndex
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
Mutably borrows from an owned value. Read more