#[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 VarZeroVecs 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::ule::*;
use zerovec::VarZeroVec;
use zerovec::ZeroSlice;
use zerovec::ZeroVec;

// 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]);

VarZeroVecs 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 of indices (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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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>

source

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());
source

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");
source

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().

source

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");
source

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();
source

pub fn as_slice(&self) -> &VarZeroSlice<T, F>

Obtain this VarZeroVec as a VarZeroSlice

source

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);
source

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>>§

source

pub(crate) fn as_components<'a>(&'a self) -> VarZeroVecComponents<'a, T, F>

Obtain a VarZeroVecComponents borrowing from the internal buffer

source

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);
source

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());
source

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");
source

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);
source

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");
}
source

pub fn to_vec(&self) -> Vec<Box<T>>

Obtain an owned Vec<Box<T>> out of this

source

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());
source

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

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));
source

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);
source

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));
source

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>

source§

fn clone(&self) -> Self

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<T, F: VarZeroVecFormat> Debug for VarZeroVec<'_, T, F>where T: Debug + VarULE + ?Sized,

source§

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

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

impl<T: VarULE + ?Sized> Default for VarZeroVec<'_, T>

source§

fn default() -> Self

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

impl<T: VarULE + ?Sized, F: VarZeroVecFormat> Deref for VarZeroVec<'_, T, F>

§

type Target = VarZeroSlice<T, F>

The resulting type after dereferencing.
source§

fn deref(&self) -> &VarZeroSlice<T, F>

Dereferences the value.
source§

impl<T, F> EncodeAsVarULE<VarZeroSlice<T, F>> for VarZeroVec<'_, T, F>where T: VarULE + ?Sized, F: VarZeroVecFormat,

source§

fn encode_var_ule_as_slices<R>(&self, _: impl FnOnce(&[&[u8]]) -> R) -> R

Calls cb with a piecewise list of byte slices that when concatenated produce the memory pattern of the corresponding instance of T. Read more
source§

fn encode_var_ule_len(&self) -> usize

Return the length, in bytes, of the corresponding VarULE type
source§

fn encode_var_ule_write(&self, dst: &mut [u8])

Write the corresponding 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>where T: VarULE + ?Sized, A: EncodeAsVarULE<T>, F: VarZeroVecFormat,

source§

fn from(elements: &[A]) -> Self

Converts to this type from the input type.
source§

impl<A, T, F, const N: usize> From<&[A; N]> for VarZeroVec<'static, T, F>where T: VarULE + ?Sized, A: EncodeAsVarULE<T>, F: VarZeroVecFormat,

source§

fn from(elements: &[A; N]) -> Self

Converts to this type from the input type.
source§

impl<'a, T: ?Sized, F> From<&'a VarZeroSlice<T, F>> for VarZeroVec<'a, T, F>

source§

fn from(other: &'a VarZeroSlice<T, F>) -> Self

Converts to this type from the input type.
source§

impl<A, T, F> From<&Vec<A, Global>> for VarZeroVec<'static, T, F>where T: VarULE + ?Sized, A: EncodeAsVarULE<T>, F: VarZeroVecFormat,

source§

fn from(elements: &Vec<A>) -> Self

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

impl<'a, T: ?Sized, F> From<VarZeroVecOwned<T, F>> for VarZeroVec<'a, T, F>

source§

fn from(other: VarZeroVecOwned<T, F>) -> Self

Converts to this type from the input type.
source§

impl<'a, T, F> MutableZeroVecLike<'a, T> for VarZeroVec<'a, T, F>where T: VarULE + ?Sized, F: VarZeroVecFormat,

§

type OwnedType = Box<T, Global>

The type returned by Self::remove() and Self::replace()
source§

fn zvl_insert(&mut self, index: usize, value: &T)

Insert an element at index
source§

fn zvl_remove(&mut self, index: usize) -> Box<T>

Remove the element at index (panicking if nonexistant)
source§

fn zvl_replace(&mut self, index: usize, value: &T) -> Box<T>

Replace the element at index with another one, returning the old element
source§

fn zvl_push(&mut self, value: &T)

Push an element to the end of this vector
source§

fn zvl_with_capacity(cap: usize) -> Self

Create a new, empty vector, with given capacity
source§

fn zvl_clear(&mut self)

Remove all elements from the vector
source§

fn zvl_reserve(&mut self, addl: usize)

Reserve space for addl additional elements
source§

fn owned_as_t(o: &Self::OwnedType) -> &T

Convert an owned value to a borrowed T
source§

fn zvl_from_borrowed(b: &'a VarZeroSlice<T, F>) -> Self

Construct from the borrowed version of the type Read more
source§

fn zvl_as_borrowed_inner(&self) -> Option<&'a VarZeroSlice<T, F>>

Extract the inner borrowed variant if possible. Returns None if the data is owned. Read more
source§

fn zvl_permute(&mut self, permutation: &mut [usize])

Applies the permutation such that before.zvl_get(permutation[i]) == after.zvl_get(i). Read more
source§

impl<'a, T: VarULE + ?Sized + Ord, F: VarZeroVecFormat> Ord for VarZeroVec<'a, T, F>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<T, A, F> PartialEq<&[A]> for VarZeroVec<'_, T, F>where T: VarULE + ?Sized + PartialEq, A: AsRef<T>, F: VarZeroVecFormat,

source§

fn eq(&self, other: &&[A]) -> 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<T, A, F, const N: usize> PartialEq<[A; N]> for VarZeroVec<'_, T, F>where T: VarULE + ?Sized + PartialEq, A: AsRef<T>, F: VarZeroVecFormat,

source§

fn eq(&self, other: &[A; N]) -> 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<'a, 'b, T, F> PartialEq<VarZeroVec<'b, T, F>> for VarZeroVec<'a, T, F>where T: VarULE + ?Sized + PartialEq, F: VarZeroVecFormat,

source§

fn eq(&self, other: &VarZeroVec<'b, T, F>) -> 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<'a, T: VarULE + ?Sized + PartialOrd, F: VarZeroVecFormat> PartialOrd<VarZeroVec<'a, T, F>> for VarZeroVec<'a, T, F>

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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 more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

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, Index16>

This type MUST be Self with the 'static replaced with 'a, i.e. Self<'a>
source§

fn transform(&'a self) -> &'a Self::Output

This method must cast self between &'a Self<'static> and &'a Self<'a>. Read more
source§

fn transform_owned(self) -> Self::Output

This method must cast self between Self<'static> and Self<'a>. Read more
source§

unsafe fn make(from: Self::Output) -> Self

This method can be used to cast away Self<'a>’s lifetime. Read more
source§

fn transform_mut<F>(&'a mut self, f: F)where F: 'static + for<'b> FnOnce(&'b mut Self::Output),

This method must cast self between &'a mut Self<'static> and &'a mut Self<'a>, and pass it to f. Read more
source§

impl<'zf, T> ZeroFrom<'zf, VarZeroSlice<T, Index16>> for VarZeroVec<'zf, T>where T: 'static + VarULE + ?Sized,

source§

fn zero_from(other: &'zf VarZeroSlice<T>) -> Self

Clone the other C into a struct that may retain references into C.
source§

impl<'zf, T> ZeroFrom<'zf, VarZeroVec<'_, T, Index16>> for VarZeroVec<'zf, T>where T: 'static + VarULE + ?Sized,

source§

fn zero_from(other: &'zf VarZeroVec<'_, T>) -> Self

Clone the other C into a struct that may retain references into C.
source§

impl<'a, T, F> ZeroVecLike<T> for VarZeroVec<'a, T, F>where T: VarULE + ?Sized, F: VarZeroVecFormat,

§

type GetType = T

The type returned by Self::get()
§

type SliceVariant = VarZeroSlice<T, F>

A fully borrowed version of this
source§

fn zvl_new_borrowed() -> &'static Self::SliceVariant

Create a new, empty borrowed variant
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.
source§

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.
source§

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.
source§

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.
source§

fn zvl_get(&self, index: usize) -> Option<&T>

Get element at index
source§

fn zvl_len(&self) -> usize

The length of this vector
source§

fn zvl_as_borrowed(&self) -> &VarZeroSlice<T, F>

Construct a borrowed variant by borrowing from &self. Read more
source§

fn zvl_get_as_t<R>(g: &Self::GetType, f: impl FnOnce(&T) -> R) -> R

Obtain a reference to T, passed to a closure Read more
source§

fn zvl_is_empty(&self) -> bool

Check if this vector is empty
source§

impl<'a, T, F> Eq for VarZeroVec<'a, T, F>where T: VarULE + ?Sized + Eq, F: VarZeroVecFormat,

Auto Trait Implementations§

§

impl<'a, T: ?Sized, F> RefUnwindSafe for VarZeroVec<'a, T, F>where F: RefUnwindSafe, T: RefUnwindSafe,

§

impl<'a, T: ?Sized, F> Send for VarZeroVec<'a, T, F>where F: Send + Sync, T: Send + Sync,

§

impl<'a, T: ?Sized, F> Sync for VarZeroVec<'a, T, F>where F: Sync, T: Sync,

§

impl<'a, T: ?Sized, F> Unpin for VarZeroVec<'a, T, F>where F: Unpin,

§

impl<'a, T: ?Sized, F> UnwindSafe for VarZeroVec<'a, T, F>where F: UnwindSafe + RefUnwindSafe, T: UnwindSafe + RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere 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 Twhere 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 Twhere 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.
source§

impl<T> ErasedDestructor for Twhere T: 'static,