Enum zerovec::VarZeroVec
source · #[non_exhaustive]pub enum VarZeroVec<'a, T: ?Sized, F = Index16> {
Owned(VarZeroVecOwned<T, F>),
Borrowed(&'a VarZeroSlice<T, F>),
}
Expand description
A zero-copy, byte-aligned vector for variable-width types.
VarZeroVec<T>
is designed as a drop-in replacement for Vec<T>
in situations where it is
desirable to borrow data from an unaligned byte slice, such as zero-copy deserialization, and
where T
’s data is variable-length (e.g. String
)
T
must implement VarULE
, which is already implemented for str
and [u8]
. For storing more
complicated series of elements, it is implemented on ZeroSlice<T>
as well as VarZeroSlice<T>
for nesting. zerovec::make_varule
may be used to generate
a dynamically-sized VarULE
type and conversions to and from a custom type.
For example, here are some owned types and their zero-copy equivalents:
Vec<String>
:VarZeroVec<'a, str>
Vec<Vec<u8>>>
:VarZeroVec<'a, [u8]>
Vec<Vec<u32>>
:VarZeroVec<'a, ZeroSlice<u32>>
Vec<Vec<String>>
:VarZeroVec<'a, VarZeroSlice<str>>
Most of the methods on VarZeroVec<'a, T>
come from its Deref
implementation to VarZeroSlice<T>
.
For creating zero-copy vectors of fixed-size types, see ZeroVec
.
VarZeroVec<T>
behaves much like Cow
, where it can be constructed from
owned data (and then mutated!) but can also borrow from some buffer.
The F
type parameter is a VarZeroVecFormat
(see its docs for more details), which can be used to select the
precise format of the backing buffer with various size and performance tradeoffs. It defaults to Index16
.
§Bytes and Equality
Two VarZeroVec
s are equal if and only if their bytes are equal, as described in the trait
VarULE
. However, we do not guarantee stability of byte equality or serialization format
across major SemVer releases.
To compare a Vec<T>
to a VarZeroVec<T>
, it is generally recommended to use
Iterator::eq
, since it is somewhat expensive at runtime to convert from a Vec<T>
to a
VarZeroVec<T>
or vice-versa.
Prior to zerovec reaching 1.0, the precise byte representation of VarZeroVec
is still
under consideration, with different options along the space-time spectrum. See
#1410.
§Example
use zerovec::VarZeroVec;
// The little-endian bytes correspond to the list of strings.
let strings = vec!["w", "ω", "文", "𑄃"];
#[derive(serde::Serialize, serde::Deserialize)]
struct Data<'a> {
#[serde(borrow)]
strings: VarZeroVec<'a, str>,
}
let data = Data {
strings: VarZeroVec::from(&strings),
};
let bincode_bytes =
bincode::serialize(&data).expect("Serialization should be successful");
// Will deserialize without allocations
let deserialized: Data = bincode::deserialize(&bincode_bytes)
.expect("Deserialization should be successful");
assert_eq!(deserialized.strings.get(2), Some("文"));
assert_eq!(deserialized.strings, &*strings);
Here’s another example with ZeroSlice<T>
(similar to [T]
):
use zerovec::VarZeroVec;
use zerovec::ZeroSlice;
// The structured list correspond to the list of integers.
let numbers: &[&[u32]] = &[
&[12, 25, 38],
&[39179, 100],
&[42, 55555],
&[12345, 54321, 9],
];
#[derive(serde::Serialize, serde::Deserialize)]
struct Data<'a> {
#[serde(borrow)]
vecs: VarZeroVec<'a, ZeroSlice<u32>>,
}
let data = Data {
vecs: VarZeroVec::from(numbers),
};
let bincode_bytes =
bincode::serialize(&data).expect("Serialization should be successful");
let deserialized: Data = bincode::deserialize(&bincode_bytes)
.expect("Deserialization should be successful");
assert_eq!(deserialized.vecs[0].get(1).unwrap(), 25);
assert_eq!(deserialized.vecs[1], *numbers[1]);
VarZeroVec
s can be nested infinitely via a similar mechanism, see the docs of VarZeroSlice
for more information.
§How it Works
VarZeroVec<T>
, when used with non-human-readable serializers (like bincode
), will
serialize to a specially formatted list of bytes. The format is:
- 4 bytes for
length
(interpreted as a little-endian u32) 4 * length
bytes ofindices
(interpreted as little-endian u32)- Remaining bytes for actual
data
Each element in the indices
array points to the starting index of its corresponding
data part in the data
list. The ending index can be calculated from the starting index
of the next element (or the length of the slice if dealing with the last element).
See the design doc for more details.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Owned(VarZeroVecOwned<T, F>)
An allocated VarZeroVec, allowing for mutations.
§Examples
use zerovec::VarZeroVec;
let mut vzv = VarZeroVec::<str>::default();
vzv.make_mut().push("foo");
vzv.make_mut().push("bar");
assert!(matches!(vzv, VarZeroVec::Owned(_)));
Borrowed(&'a VarZeroSlice<T, F>)
A borrowed VarZeroVec, requiring no allocations.
If a mutating operation is invoked on VarZeroVec, the Borrowed is converted to Owned.
§Examples
use zerovec::VarZeroVec;
let bytes = &[
4, 0, 0, 0, 0, 0, 1, 0, 3, 0, 6, 0, 119, 207, 137, 230, 150, 135, 240,
145, 132, 131,
];
let vzv: VarZeroVec<str> = VarZeroVec::parse_byte_slice(bytes).unwrap();
assert!(matches!(vzv, VarZeroVec::Borrowed(_)));
Implementations§
source§impl<'a, T: VarULE + ?Sized, F: VarZeroVecFormat> VarZeroVec<'a, T, F>
impl<'a, T: VarULE + ?Sized, F: VarZeroVecFormat> VarZeroVec<'a, T, F>
sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new, empty VarZeroVec<T>
.
§Examples
use zerovec::VarZeroVec;
let vzv: VarZeroVec<str> = VarZeroVec::new();
assert!(vzv.is_empty());
sourcepub fn parse_byte_slice(slice: &'a [u8]) -> Result<Self, ZeroVecError>
pub fn parse_byte_slice(slice: &'a [u8]) -> Result<Self, ZeroVecError>
Parse a VarZeroVec from a slice of the appropriate format
Slices of the right format can be obtained via VarZeroSlice::as_bytes()
.
§Example
let strings = vec!["foo", "bar", "baz", "quux"];
let vec = VarZeroVec::<str>::from(&strings);
assert_eq!(&vec[0], "foo");
assert_eq!(&vec[1], "bar");
assert_eq!(&vec[2], "baz");
assert_eq!(&vec[3], "quux");
sourcepub const unsafe fn from_bytes_unchecked(bytes: &'a [u8]) -> Self
pub const unsafe fn from_bytes_unchecked(bytes: &'a [u8]) -> Self
Uses a &[u8]
buffer as a VarZeroVec<T>
without any verification.
§Safety
bytes
need to be an output from VarZeroSlice::as_bytes()
.
sourcepub fn make_mut(&mut self) -> &mut VarZeroVecOwned<T, F>
pub fn make_mut(&mut self) -> &mut VarZeroVecOwned<T, F>
Convert this into a mutable vector of the owned T
type, cloning if necessary.
§Example
let strings = vec!["foo", "bar", "baz", "quux"];
let mut vec = VarZeroVec::<str>::from(&strings);
assert_eq!(vec.len(), 4);
let mutvec = vec.make_mut();
mutvec.push("lorem ipsum".into());
mutvec[2] = "dolor sit".into();
assert_eq!(&vec[0], "foo");
assert_eq!(&vec[1], "bar");
assert_eq!(&vec[2], "dolor sit");
assert_eq!(&vec[3], "quux");
assert_eq!(&vec[4], "lorem ipsum");
sourcepub fn into_owned(self) -> VarZeroVec<'static, T, F>
pub fn into_owned(self) -> VarZeroVec<'static, T, F>
Converts a borrowed ZeroVec to an owned ZeroVec. No-op if already owned.
§Example
let strings = vec!["foo", "bar", "baz", "quux"];
let vec = VarZeroVec::<str>::from(&strings);
assert_eq!(vec.len(), 4);
// has 'static lifetime
let owned = vec.into_owned();
sourcepub fn as_slice(&self) -> &VarZeroSlice<T, F>
pub fn as_slice(&self) -> &VarZeroSlice<T, F>
Obtain this VarZeroVec
as a VarZeroSlice
sourcepub fn into_bytes(self) -> Vec<u8>
pub fn into_bytes(self) -> Vec<u8>
Takes the byte vector representing the encoded data of this VarZeroVec. If borrowed, this function allocates a byte vector and copies the borrowed bytes into it.
The bytes can be passed back to Self::parse_byte_slice()
.
To get a reference to the bytes without moving, see VarZeroSlice::as_bytes()
.
§Example
let strings = vec!["foo", "bar", "baz"];
let bytes = VarZeroVec::<str>::from(&strings).into_bytes();
let mut borrowed: VarZeroVec<str> = VarZeroVec::parse_byte_slice(&bytes)?;
assert_eq!(borrowed, &*strings);
sourcepub fn is_owned(&self) -> bool
pub fn is_owned(&self) -> bool
Return whether the VarZeroVec
is operating on owned or borrowed
data. VarZeroVec::into_owned()
and VarZeroVec::make_mut()
can
be used to force it into an owned type
Methods from Deref<Target = VarZeroSlice<T, F>>§
sourcepub(crate) fn as_components<'a>(&'a self) -> VarZeroVecComponents<'a, T, F>
pub(crate) fn as_components<'a>(&'a self) -> VarZeroVecComponents<'a, T, F>
Obtain a VarZeroVecComponents
borrowing from the internal buffer
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the number of elements in this slice
§Example
let strings = vec!["foo", "bar", "baz", "quux"];
let vec = VarZeroVec::<str>::from(&strings);
assert_eq!(vec.len(), 4);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the slice contains no elements.
§Examples
let strings: Vec<String> = vec![];
let vec = VarZeroVec::<str>::from(&strings);
assert!(vec.is_empty());
sourcepub fn iter<'b>(&'b self) -> impl Iterator<Item = &'b T>
pub fn iter<'b>(&'b self) -> impl Iterator<Item = &'b T>
Obtain an iterator over this slice’s elements
§Example
let strings = vec!["foo", "bar", "baz", "quux"];
let vec = VarZeroVec::<str>::from(&strings);
let mut iter_results: Vec<&str> = vec.iter().collect();
assert_eq!(iter_results[0], "foo");
assert_eq!(iter_results[1], "bar");
assert_eq!(iter_results[2], "baz");
assert_eq!(iter_results[3], "quux");
sourcepub fn get(&self, idx: usize) -> Option<&T>
pub fn get(&self, idx: usize) -> Option<&T>
Get one of this slice’s elements, returning None
if the index is out of bounds
§Example
let strings = vec!["foo", "bar", "baz", "quux"];
let vec = VarZeroVec::<str>::from(&strings);
let mut iter_results: Vec<&str> = vec.iter().collect();
assert_eq!(vec.get(0), Some("foo"));
assert_eq!(vec.get(1), Some("bar"));
assert_eq!(vec.get(2), Some("baz"));
assert_eq!(vec.get(3), Some("quux"));
assert_eq!(vec.get(4), None);
sourcepub unsafe fn get_unchecked(&self, idx: usize) -> &T
pub unsafe fn get_unchecked(&self, idx: usize) -> &T
Get one of this slice’s elements
§Safety
index
must be in range
§Example
let strings = vec!["foo", "bar", "baz", "quux"];
let vec = VarZeroVec::<str>::from(&strings);
let mut iter_results: Vec<&str> = vec.iter().collect();
unsafe {
assert_eq!(vec.get_unchecked(0), "foo");
assert_eq!(vec.get_unchecked(1), "bar");
assert_eq!(vec.get_unchecked(2), "baz");
assert_eq!(vec.get_unchecked(3), "quux");
}
sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Get a reference to the entire encoded backing buffer of this slice
The bytes can be passed back to Self::parse_byte_slice()
.
To take the bytes as a vector, see VarZeroVec::into_bytes()
.
§Example
let strings = vec!["foo", "bar", "baz"];
let vzv = VarZeroVec::<str>::from(&strings);
assert_eq!(vzv, VarZeroVec::parse_byte_slice(vzv.as_bytes()).unwrap());
sourcepub fn as_varzerovec<'a>(&'a self) -> VarZeroVec<'a, T, F>
pub fn as_varzerovec<'a>(&'a self) -> VarZeroVec<'a, T, F>
Get this VarZeroSlice
as a borrowed VarZeroVec
If you wish to repeatedly call methods on this VarZeroSlice
,
it is more efficient to perform this conversion first
sourcepub fn binary_search(&self, x: &T) -> Result<usize, usize>
pub fn binary_search(&self, x: &T) -> Result<usize, usize>
Binary searches a sorted VarZeroVec<T>
for the given element. For more information, see
the standard library function binary_search
.
§Example
let strings = vec!["a", "b", "f", "g"];
let vec = VarZeroVec::<str>::from(&strings);
assert_eq!(vec.binary_search("f"), Ok(2));
assert_eq!(vec.binary_search("e"), Err(2));
sourcepub fn binary_search_in_range(
&self,
x: &T,
range: Range<usize>,
) -> Option<Result<usize, usize>>
pub fn binary_search_in_range( &self, x: &T, range: Range<usize>, ) -> Option<Result<usize, usize>>
Binary searches a VarZeroVec<T>
for the given element within a certain sorted range.
If the range is out of bounds, returns None
. Otherwise, returns a Result
according
to the behavior of the standard library function binary_search
.
The index is returned relative to the start of the range.
§Example
let strings = vec!["a", "b", "f", "g", "m", "n", "q"];
let vec = VarZeroVec::<str>::from(&strings);
// Same behavior as binary_search when the range covers the whole slice:
assert_eq!(vec.binary_search_in_range("g", 0..7), Some(Ok(3)));
assert_eq!(vec.binary_search_in_range("h", 0..7), Some(Err(4)));
// Will not look outside of the range:
assert_eq!(vec.binary_search_in_range("g", 0..1), Some(Err(1)));
assert_eq!(vec.binary_search_in_range("g", 6..7), Some(Err(0)));
// Will return indices relative to the start of the range:
assert_eq!(vec.binary_search_in_range("g", 1..6), Some(Ok(2)));
assert_eq!(vec.binary_search_in_range("h", 1..6), Some(Err(3)));
// Will return `None` if the range is out of bounds:
assert_eq!(vec.binary_search_in_range("x", 100..200), None);
assert_eq!(vec.binary_search_in_range("x", 0..200), None);
sourcepub fn binary_search_by(
&self,
predicate: impl FnMut(&T) -> Ordering,
) -> Result<usize, usize>
pub fn binary_search_by( &self, predicate: impl FnMut(&T) -> Ordering, ) -> Result<usize, usize>
Binary searches a sorted VarZeroVec<T>
for the given predicate. For more information, see
the standard library function binary_search_by
.
§Example
let strings = vec!["a", "b", "f", "g"];
let vec = VarZeroVec::<str>::from(&strings);
assert_eq!(vec.binary_search_by(|probe| probe.cmp("f")), Ok(2));
assert_eq!(vec.binary_search_by(|probe| probe.cmp("e")), Err(2));
sourcepub fn binary_search_in_range_by(
&self,
predicate: impl FnMut(&T) -> Ordering,
range: Range<usize>,
) -> Option<Result<usize, usize>>
pub fn binary_search_in_range_by( &self, predicate: impl FnMut(&T) -> Ordering, range: Range<usize>, ) -> Option<Result<usize, usize>>
Binary searches a VarZeroVec<T>
for the given predicate within a certain sorted range.
If the range is out of bounds, returns None
. Otherwise, returns a Result
according
to the behavior of the standard library function binary_search
.
The index is returned relative to the start of the range.
§Example
let strings = vec!["a", "b", "f", "g", "m", "n", "q"];
let vec = VarZeroVec::<str>::from(&strings);
// Same behavior as binary_search when the range covers the whole slice:
assert_eq!(
vec.binary_search_in_range_by(|v| v.cmp("g"), 0..7),
Some(Ok(3))
);
assert_eq!(
vec.binary_search_in_range_by(|v| v.cmp("h"), 0..7),
Some(Err(4))
);
// Will not look outside of the range:
assert_eq!(
vec.binary_search_in_range_by(|v| v.cmp("g"), 0..1),
Some(Err(1))
);
assert_eq!(
vec.binary_search_in_range_by(|v| v.cmp("g"), 6..7),
Some(Err(0))
);
// Will return indices relative to the start of the range:
assert_eq!(
vec.binary_search_in_range_by(|v| v.cmp("g"), 1..6),
Some(Ok(2))
);
assert_eq!(
vec.binary_search_in_range_by(|v| v.cmp("h"), 1..6),
Some(Err(3))
);
// Will return `None` if the range is out of bounds:
assert_eq!(
vec.binary_search_in_range_by(|v| v.cmp("x"), 100..200),
None
);
assert_eq!(vec.binary_search_in_range_by(|v| v.cmp("x"), 0..200), None);
Trait Implementations§
source§impl<'a, T: ?Sized, F> Clone for VarZeroVec<'a, T, F>
impl<'a, T: ?Sized, F> Clone for VarZeroVec<'a, T, F>
source§impl<T, F: VarZeroVecFormat> Debug for VarZeroVec<'_, T, F>
impl<T, F: VarZeroVecFormat> Debug for VarZeroVec<'_, T, F>
source§impl<T: VarULE + ?Sized, F: VarZeroVecFormat> Deref for VarZeroVec<'_, T, F>
impl<T: VarULE + ?Sized, F: VarZeroVecFormat> Deref for VarZeroVec<'_, T, F>
§type Target = VarZeroSlice<T, F>
type Target = VarZeroSlice<T, F>
source§fn deref(&self) -> &VarZeroSlice<T, F>
fn deref(&self) -> &VarZeroSlice<T, F>
source§impl<T, F> EncodeAsVarULE<VarZeroSlice<T, F>> for VarZeroVec<'_, T, F>
impl<T, F> EncodeAsVarULE<VarZeroSlice<T, F>> for VarZeroVec<'_, T, F>
source§fn encode_var_ule_as_slices<R>(&self, _: impl FnOnce(&[&[u8]]) -> R) -> R
fn encode_var_ule_as_slices<R>(&self, _: impl FnOnce(&[&[u8]]) -> R) -> R
cb
with a piecewise list of byte slices that when concatenated
produce the memory pattern of the corresponding instance of T
. Read moresource§fn encode_var_ule_len(&self) -> usize
fn encode_var_ule_len(&self) -> usize
VarULE
typesource§fn encode_var_ule_write(&self, dst: &mut [u8])
fn encode_var_ule_write(&self, dst: &mut [u8])
VarULE
type to the dst
buffer. dst
should
be the size of Self::encode_var_ule_len()
source§impl<A, T, F> From<&[A]> for VarZeroVec<'static, T, F>
impl<A, T, F> From<&[A]> for VarZeroVec<'static, T, F>
source§impl<'a, T: ?Sized, F> From<&'a VarZeroSlice<T, F>> for VarZeroVec<'a, T, F>
impl<'a, T: ?Sized, F> From<&'a VarZeroSlice<T, F>> for VarZeroVec<'a, T, F>
source§fn from(other: &'a VarZeroSlice<T, F>) -> Self
fn from(other: &'a VarZeroSlice<T, F>) -> Self
source§impl<A, T, F> From<&Vec<A>> for VarZeroVec<'static, T, F>
impl<A, T, F> From<&Vec<A>> for VarZeroVec<'static, T, F>
source§impl<'a, T: ?Sized + VarULE, F: VarZeroVecFormat> From<VarZeroVec<'a, T, F>> for VarZeroVecOwned<T, F>
impl<'a, T: ?Sized + VarULE, F: VarZeroVecFormat> From<VarZeroVec<'a, T, F>> for VarZeroVecOwned<T, F>
source§fn from(other: VarZeroVec<'a, T, F>) -> Self
fn from(other: VarZeroVec<'a, T, F>) -> Self
source§impl<'a, T: ?Sized, F> From<VarZeroVecOwned<T, F>> for VarZeroVec<'a, T, F>
impl<'a, T: ?Sized, F> From<VarZeroVecOwned<T, F>> for VarZeroVec<'a, T, F>
source§fn from(other: VarZeroVecOwned<T, F>) -> Self
fn from(other: VarZeroVecOwned<T, F>) -> Self
source§impl<'a, T, F> MutableZeroVecLike<'a, T> for VarZeroVec<'a, T, F>
impl<'a, T, F> MutableZeroVecLike<'a, T> for VarZeroVec<'a, T, F>
source§fn zvl_insert(&mut self, index: usize, value: &T)
fn zvl_insert(&mut self, index: usize, value: &T)
index
source§fn zvl_remove(&mut self, index: usize) -> Box<T>
fn zvl_remove(&mut self, index: usize) -> Box<T>
index
(panicking if nonexistant)source§fn zvl_replace(&mut self, index: usize, value: &T) -> Box<T>
fn zvl_replace(&mut self, index: usize, value: &T) -> Box<T>
index
with another one, returning the old elementsource§fn zvl_with_capacity(cap: usize) -> Self
fn zvl_with_capacity(cap: usize) -> Self
source§fn zvl_reserve(&mut self, addl: usize)
fn zvl_reserve(&mut self, addl: usize)
addl
additional elementssource§fn owned_as_t(o: &Self::OwnedType) -> &T
fn owned_as_t(o: &Self::OwnedType) -> &T
source§fn zvl_from_borrowed(b: &'a VarZeroSlice<T, F>) -> Self
fn zvl_from_borrowed(b: &'a VarZeroSlice<T, F>) -> Self
source§fn zvl_as_borrowed_inner(&self) -> Option<&'a VarZeroSlice<T, F>>
fn zvl_as_borrowed_inner(&self) -> Option<&'a VarZeroSlice<T, F>>
None
if the data is owned. Read moresource§fn zvl_permute(&mut self, permutation: &mut [usize])
fn zvl_permute(&mut self, permutation: &mut [usize])
before.zvl_get(permutation[i]) == after.zvl_get(i)
. Read moresource§impl<'a, T: VarULE + ?Sized + Ord, F: VarZeroVecFormat> Ord for VarZeroVec<'a, T, F>
impl<'a, T: VarULE + ?Sized + Ord, F: VarZeroVecFormat> Ord for VarZeroVec<'a, T, F>
source§impl<T, A, F> PartialEq<&[A]> for VarZeroVec<'_, T, F>
impl<T, A, F> PartialEq<&[A]> for VarZeroVec<'_, T, F>
source§impl<T, A, F, const N: usize> PartialEq<[A; N]> for VarZeroVec<'_, T, F>
impl<T, A, F, const N: usize> PartialEq<[A; N]> for VarZeroVec<'_, T, F>
source§impl<'a, 'b, T, F> PartialEq<VarZeroVec<'b, T, F>> for VarZeroVec<'a, T, F>
impl<'a, 'b, T, F> PartialEq<VarZeroVec<'b, T, F>> for VarZeroVec<'a, T, F>
source§fn eq(&self, other: &VarZeroVec<'b, T, F>) -> bool
fn eq(&self, other: &VarZeroVec<'b, T, F>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'a, T: VarULE + ?Sized + PartialOrd, F: VarZeroVecFormat> PartialOrd for VarZeroVec<'a, T, F>
impl<'a, T: VarULE + ?Sized + PartialOrd, F: VarZeroVecFormat> PartialOrd for VarZeroVec<'a, T, F>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<'a, T: 'static + VarULE + ?Sized> Yokeable<'a> for VarZeroVec<'static, T>
impl<'a, T: 'static + VarULE + ?Sized> Yokeable<'a> for VarZeroVec<'static, T>
This impl requires enabling the optional yoke
Cargo feature of the zerovec
crate
§type Output = VarZeroVec<'a, T>
type Output = VarZeroVec<'a, T>
Self
with the 'static
replaced with 'a
, i.e. Self<'a>
source§fn transform_owned(self) -> Self::Output
fn transform_owned(self) -> Self::Output
source§impl<'zf, T> ZeroFrom<'zf, VarZeroSlice<T>> for VarZeroVec<'zf, T>
impl<'zf, T> ZeroFrom<'zf, VarZeroSlice<T>> for VarZeroVec<'zf, T>
source§fn zero_from(other: &'zf VarZeroSlice<T>) -> Self
fn zero_from(other: &'zf VarZeroSlice<T>) -> Self
C
into a struct that may retain references into C
.source§impl<'zf, T> ZeroFrom<'zf, VarZeroVec<'_, T>> for VarZeroVec<'zf, T>
impl<'zf, T> ZeroFrom<'zf, VarZeroVec<'_, T>> for VarZeroVec<'zf, T>
source§fn zero_from(other: &'zf VarZeroVec<'_, T>) -> Self
fn zero_from(other: &'zf VarZeroVec<'_, T>) -> Self
C
into a struct that may retain references into C
.source§impl<'a, T, F> ZeroVecLike<T> for VarZeroVec<'a, T, F>
impl<'a, T, F> ZeroVecLike<T> for VarZeroVec<'a, T, F>
§type SliceVariant = VarZeroSlice<T, F>
type SliceVariant = VarZeroSlice<T, F>
source§fn zvl_new_borrowed() -> &'static Self::SliceVariant
fn zvl_new_borrowed() -> &'static Self::SliceVariant
source§fn 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,
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.source§fn 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,
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.source§fn 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>
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.source§fn 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>>
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.source§fn zvl_as_borrowed(&self) -> &VarZeroSlice<T, F>
fn zvl_as_borrowed(&self) -> &VarZeroSlice<T, F>
&self
. Read more