Trait zerovec::maps::ZeroVecLike
source · pub trait ZeroVecLike<T: ?Sized> {
type GetType: ?Sized + 'static;
type SliceVariant: ZeroVecLike<T, GetType = Self::GetType> + ?Sized;
Show 13 methods
// Required methods
fn zvl_new_borrowed() -> &'static Self::SliceVariant;
fn zvl_binary_search(&self, k: &T) -> Result<usize, usize>
where T: Ord;
fn zvl_binary_search_in_range(
&self,
k: &T,
range: Range<usize>,
) -> Option<Result<usize, usize>>
where T: Ord;
fn zvl_binary_search_by(
&self,
predicate: impl FnMut(&T) -> Ordering,
) -> Result<usize, usize>;
fn zvl_binary_search_in_range_by(
&self,
predicate: impl FnMut(&T) -> Ordering,
range: Range<usize>,
) -> Option<Result<usize, usize>>;
fn zvl_get(&self, index: usize) -> Option<&Self::GetType>;
fn zvl_len(&self) -> usize;
fn zvl_as_borrowed(&self) -> &Self::SliceVariant;
fn zvl_get_as_t<R>(g: &Self::GetType, f: impl FnOnce(&T) -> R) -> R;
// Provided methods
fn zvl_is_ascending(&self) -> bool
where T: Ord { ... }
fn zvl_is_empty(&self) -> bool { ... }
fn t_cmp_get(t: &T, g: &Self::GetType) -> Ordering
where T: Ord { ... }
fn get_cmp_get(a: &Self::GetType, b: &Self::GetType) -> Ordering
where T: Ord { ... }
}
Expand description
Trait abstracting over ZeroVec
and VarZeroVec
, for use in ZeroMap
. You
should not be implementing or calling this trait directly.
The T type is the type received by Self::zvl_binary_search()
, as well as the one used
for human-readable serialization.
Methods are prefixed with zvl_*
to avoid clashes with methods on the types themselves
Required Associated Types§
sourcetype SliceVariant: ZeroVecLike<T, GetType = Self::GetType> + ?Sized
type SliceVariant: ZeroVecLike<T, GetType = Self::GetType> + ?Sized
A fully borrowed version of this
Required Methods§
sourcefn zvl_new_borrowed() -> &'static Self::SliceVariant
fn zvl_new_borrowed() -> &'static Self::SliceVariant
Create a new, empty borrowed variant
sourcefn zvl_binary_search(&self, k: &T) -> Result<usize, usize>where
T: Ord,
fn zvl_binary_search(&self, k: &T) -> Result<usize, usize>where
T: Ord,
Search for a key in a sorted vector, returns Ok(index)
if found,
returns Err(insert_index)
if not found, where insert_index
is the
index where it should be inserted to maintain sort order.
sourcefn zvl_binary_search_in_range(
&self,
k: &T,
range: Range<usize>,
) -> Option<Result<usize, usize>>where
T: Ord,
fn zvl_binary_search_in_range(
&self,
k: &T,
range: Range<usize>,
) -> Option<Result<usize, usize>>where
T: Ord,
Search for a key within a certain range in a sorted vector.
Returns None
if the range is out of bounds, and
Ok
or Err
in the same way as zvl_binary_search
.
Indices are returned relative to the start of the range.
sourcefn zvl_binary_search_by(
&self,
predicate: impl FnMut(&T) -> Ordering,
) -> Result<usize, usize>
fn zvl_binary_search_by( &self, predicate: impl FnMut(&T) -> Ordering, ) -> Result<usize, usize>
Search for a key in a sorted vector by a predicate, returns Ok(index)
if found,
returns Err(insert_index)
if not found, where insert_index
is the
index where it should be inserted to maintain sort order.
sourcefn zvl_binary_search_in_range_by(
&self,
predicate: impl FnMut(&T) -> Ordering,
range: Range<usize>,
) -> Option<Result<usize, usize>>
fn zvl_binary_search_in_range_by( &self, predicate: impl FnMut(&T) -> Ordering, range: Range<usize>, ) -> Option<Result<usize, usize>>
Search for a key within a certain range in a sorted vector by a predicate.
Returns None
if the range is out of bounds, and
Ok
or Err
in the same way as zvl_binary_search
.
Indices are returned relative to the start of the range.
sourcefn zvl_as_borrowed(&self) -> &Self::SliceVariant
fn zvl_as_borrowed(&self) -> &Self::SliceVariant
Construct a borrowed variant by borrowing from &self
.
This function behaves like &'b self -> Self::SliceVariant<'b>
,
where 'b
is the lifetime of the reference to this object.
Note: We rely on the compiler recognizing 'a
and 'b
as covariant and
casting &'b Self<'a>
to &'b Self<'b>
when this gets called, which works
out for ZeroVec
and VarZeroVec
containers just fine.
sourcefn zvl_get_as_t<R>(g: &Self::GetType, f: impl FnOnce(&T) -> R) -> R
fn zvl_get_as_t<R>(g: &Self::GetType, f: impl FnOnce(&T) -> R) -> R
Obtain a reference to T, passed to a closure
This uses a callback because it’s not possible to return owned-or-borrowed types without GATs
Impls should guarantee that the callback function is be called exactly once.
Provided Methods§
sourcefn zvl_is_ascending(&self) -> boolwhere
T: Ord,
fn zvl_is_ascending(&self) -> boolwhere
T: Ord,
Check if this vector is in ascending order according to T
s Ord
impl
sourcefn zvl_is_empty(&self) -> bool
fn zvl_is_empty(&self) -> bool
Check if this vector is empty