#[repr(transparent)]pub struct ZeroSlice<T: AsULE>(_);
Expand description
A zero-copy “slice”, i.e. the zero-copy version of [T]
. This behaves
similarly to ZeroVec<T>
, however ZeroVec<T>
is allowed to contain
owned data and as such is ideal for deserialization since most human readable
serialization formats cannot unconditionally deserialize zero-copy.
This type can be used inside VarZeroVec<T>
and ZeroMap
:
This essentially allows for the construction of zero-copy types isomorphic to Vec<Vec<T>>
by instead
using VarZeroVec<ZeroSlice<T>>
. See the VarZeroVec
docs for an example.
Examples
Const-construct a ZeroSlice of u16:
use zerovec::ZeroSlice;
use zerovec::ule::AsULE;
const DATA: &ZeroSlice<u16> = ZeroSlice::<u16>::from_ule_slice_const(
&<u16 as AsULE>::ULE::from_array([211, 281, 421, 32973])
);
assert_eq!(DATA.get(1), Some(281));
Implementations
sourceimpl<T> ZeroSlice<T> where
T: AsULE,
impl<T> ZeroSlice<T> where
T: AsULE,
sourcepub fn as_zerovec(&self) -> ZeroVec<'_, T>
pub fn as_zerovec(&self) -> ZeroVec<'_, T>
sourcepub fn parse_byte_slice(bytes: &[u8]) -> Result<&Self, ZeroVecError>
pub fn parse_byte_slice(bytes: &[u8]) -> Result<&Self, ZeroVecError>
Attempt to construct a &ZeroSlice<T>
from a byte slice, returning an error
if it’s not a valid byte sequence
sourcepub fn from_ule_slice(slice: &[T::ULE]) -> &Self
pub fn from_ule_slice(slice: &[T::ULE]) -> &Self
Construct a &ZeroSlice<T>
from a slice of ULEs
sourcepub fn from_boxed_slice(slice: Box<[T::ULE]>) -> Box<Self>ⓘNotable traits for Box<R, Global>impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
pub fn from_boxed_slice(slice: Box<[T::ULE]>) -> Box<Self>ⓘNotable traits for Box<R, Global>impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
Construct a Box<ZeroSlice<T>>
from a boxed slice of ULEs
sourcepub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Returns this slice as its underlying &[u8]
byte buffer representation.
Useful for serialization.
Example
use zerovec::ZeroVec;
// The little-endian bytes correspond to the numbers on the following line.
let bytes: &[u8] = &[0xD3, 0x00, 0x19, 0x01, 0xA5, 0x01, 0xCD, 0x80];
let nums: &[u16] = &[211, 281, 421, 32973];
let zerovec = ZeroVec::alloc_from_slice(nums);
assert_eq!(bytes, zerovec.as_bytes());
sourcepub fn as_ule_slice(&self) -> &[T::ULE]
pub fn as_ule_slice(&self) -> &[T::ULE]
Dereferences this slice as &[T::ULE]
.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in this slice.
Example
use zerovec::ZeroVec;
use zerovec::ule::AsULE;
let bytes: &[u8] = &[0xD3, 0x00, 0x19, 0x01, 0xA5, 0x01, 0xCD, 0x80];
let zerovec: ZeroVec<u16> = ZeroVec::parse_byte_slice(bytes).expect("infallible");
assert_eq!(4, zerovec.len());
assert_eq!(
bytes.len(),
zerovec.len() * std::mem::size_of::<<u16 as AsULE>::ULE>()
);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether this slice is empty.
Example
use zerovec::ZeroVec;
let bytes: &[u8] = &[0xD3, 0x00, 0x19, 0x01, 0xA5, 0x01, 0xCD, 0x80];
let zerovec: ZeroVec<u16> = ZeroVec::parse_byte_slice(bytes).expect("infallible");
assert!(!zerovec.is_empty());
let emptyvec: ZeroVec<u16> = ZeroVec::parse_byte_slice(&[]).expect("infallible");
assert!(emptyvec.is_empty());
sourceimpl<T> ZeroSlice<T> where
T: AsULE,
impl<T> ZeroSlice<T> where
T: AsULE,
sourcepub fn get(&self, index: usize) -> Option<T>
pub fn get(&self, index: usize) -> Option<T>
Gets the element at the specified index. Returns None if out of range.
Example
use zerovec::ZeroVec;
let bytes: &[u8] = &[0xD3, 0x00, 0x19, 0x01, 0xA5, 0x01, 0xCD, 0x80];
let zerovec: ZeroVec<u16> = ZeroVec::parse_byte_slice(bytes).expect("infallible");
assert_eq!(zerovec.get(2), Some(421));
assert_eq!(zerovec.get(4), None);
sourcepub fn get_subslice(&self, range: Range<usize>) -> Option<&ZeroSlice<T>>
pub fn get_subslice(&self, range: Range<usize>) -> Option<&ZeroSlice<T>>
Gets a subslice of elements within a certain range. Returns None if the range
is out of bounds of this ZeroSlice
.
Example
use zerovec::ZeroVec;
let bytes: &[u8] = &[0xD3, 0x00, 0x19, 0x01, 0xA5, 0x01, 0xCD, 0x80];
let zerovec: ZeroVec<u16> = ZeroVec::parse_byte_slice(bytes).expect("infallible");
assert_eq!(
zerovec.get_subslice(1..3),
Some(&*ZeroVec::from_slice_or_alloc(&[0x0119, 0x01A5]))
);
assert_eq!(zerovec.get_subslice(3..5), None);
sourcepub fn get_ule_ref(&self, index: usize) -> Option<&T::ULE>
pub fn get_ule_ref(&self, index: usize) -> Option<&T::ULE>
Get a borrowed reference to the underlying ULE type at a specified index.
Prefer Self::get()
over this method where possible since working
directly with ULE
types is less ergonomic
sourcepub fn cast<P>(&self) -> &ZeroSlice<P> where
P: AsULE<ULE = T::ULE>,
pub fn cast<P>(&self) -> &ZeroSlice<P> where
P: AsULE<ULE = T::ULE>,
Casts a ZeroSlice<T>
to a compatible ZeroSlice<P>
.
T
and P
are compatible if they have the same ULE
representation.
If the ULE
s of T
and P
are different, use Self::try_as_converted()
.
Examples
use zerovec::ZeroSlice;
const bytes: &[u8] = &[0xD3, 0x00, 0x19, 0x01, 0xA5, 0x01, 0xCD, 0x80];
const zs_u16: &ZeroSlice<u16> = {
match ZeroSlice::<u16>::try_from_bytes(bytes) {
Ok(s) => s,
Err(_) => unreachable!()
}
};
let zs_i16: &ZeroSlice<i16> = zs_u16.cast();
assert_eq!(zs_u16.get(3), Some(32973));
assert_eq!(zs_i16.get(3), Some(-32563));
sourcepub fn try_as_converted<P: AsULE>(&self) -> Result<&ZeroSlice<P>, ZeroVecError>
pub fn try_as_converted<P: AsULE>(&self) -> Result<&ZeroSlice<P>, ZeroVecError>
Converts a &ZeroSlice<T>
into a &ZeroSlice<P>
.
The resulting slice will have the same length as the original slice
if and only if T::ULE
and P::ULE
are the same size.
If T
and P
have the exact same ULE
, use Self::cast()
.
Examples
use zerovec::ZeroSlice;
const bytes: &[u8] = &[0x7F, 0xF3, 0x01, 0x00, 0x49, 0xF6, 0x01, 0x00];
const zs_u32: &ZeroSlice<u32> = {
match ZeroSlice::<u32>::try_from_bytes(bytes) {
Ok(s) => s,
Err(_) => unreachable!()
}
};
let zs_char: &ZeroSlice<char> = zs_u32.try_as_converted()
.expect("valid code points");
assert_eq!(zs_u32.get(0), Some(u32::from('🍿')));
assert_eq!(zs_char.get(0), Some('🍿'));
sourcepub fn first(&self) -> Option<T>
pub fn first(&self) -> Option<T>
Gets the first element. Returns None if empty.
Example
use zerovec::ZeroVec;
let bytes: &[u8] = &[0xD3, 0x00, 0x19, 0x01, 0xA5, 0x01, 0xCD, 0x80];
let zerovec: ZeroVec<u16> = ZeroVec::parse_byte_slice(bytes).expect("infallible");
assert_eq!(zerovec.first(), Some(211));
sourcepub fn last(&self) -> Option<T>
pub fn last(&self) -> Option<T>
Gets the last element. Returns None if empty.
Example
use zerovec::ZeroVec;
let bytes: &[u8] = &[0xD3, 0x00, 0x19, 0x01, 0xA5, 0x01, 0xCD, 0x80];
let zerovec: ZeroVec<u16> = ZeroVec::parse_byte_slice(bytes).expect("infallible");
assert_eq!(zerovec.last(), Some(32973));
sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = T> + '_
pub fn iter(&self) -> impl DoubleEndedIterator<Item = T> + '_
Gets an iterator over the elements.
Example
use zerovec::ZeroVec;
let bytes: &[u8] = &[0xD3, 0x00, 0x19, 0x01, 0xA5, 0x01, 0xCD, 0x80];
let zerovec: ZeroVec<u16> = ZeroVec::parse_byte_slice(bytes).expect("infallible");
let mut it = zerovec.iter();
assert_eq!(it.next(), Some(211));
assert_eq!(it.next(), Some(281));
assert_eq!(it.next(), Some(421));
assert_eq!(it.next(), Some(32973));
assert_eq!(it.next(), None);
sourceimpl<T> ZeroSlice<T> where
T: AsULE + Ord,
impl<T> ZeroSlice<T> where
T: AsULE + Ord,
sourcepub fn binary_search(&self, x: &T) -> Result<usize, usize>
pub fn binary_search(&self, x: &T) -> Result<usize, usize>
Binary searches a sorted ZeroVec<T>
for the given element. For more information, see
the primitive function binary_search
.
Example
use zerovec::ZeroVec;
let bytes: &[u8] = &[0xD3, 0x00, 0x19, 0x01, 0xA5, 0x01, 0xCD, 0x80];
let zerovec: ZeroVec<u16> = ZeroVec::parse_byte_slice(bytes).expect("infallible");
assert_eq!(zerovec.binary_search(&281), Ok(1));
assert_eq!(zerovec.binary_search(&282), Err(2));
sourceimpl<T> ZeroSlice<T> where
T: AsULE,
impl<T> ZeroSlice<T> where
T: AsULE,
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 ZeroVec<T>
based on a given predicate. For more information, see
the primitive function binary_search_by
.
Example
use zerovec::ZeroVec;
let bytes: &[u8] = &[0xD3, 0x00, 0x19, 0x01, 0xA5, 0x01, 0xCD, 0x80];
let zerovec: ZeroVec<u16> = ZeroVec::parse_byte_slice(bytes).expect("infallible");
assert_eq!(zerovec.binary_search_by(|x| x.cmp(&281)), Ok(1));
assert_eq!(zerovec.binary_search_by(|x| x.cmp(&282)), Err(2));
sourceimpl ZeroSlice<u16>
impl ZeroSlice<u16>
sourcepub const fn try_from_bytes(bytes: &[u8]) -> Result<&Self, ZeroVecError>
pub const fn try_from_bytes(bytes: &[u8]) -> Result<&Self, ZeroVecError>
This function can be used for constructing ZeroVecs in a const context, avoiding parsing checks.
This cannot be generic over T because of current limitations in const
, but if
this method is needed in a non-const context, check out ZeroSlice::parse_byte_slice()
instead.
See ZeroSlice::cast()
for an example.
sourcepub const fn from_ule_slice_const(slice: &[RawBytesULE<2>]) -> &Self
pub const fn from_ule_slice_const(slice: &[RawBytesULE<2>]) -> &Self
This function can be used for constructing ZeroVecs in a const context, avoiding parsing checks.
See ZeroSlice
for an example.
sourceimpl ZeroSlice<u32>
impl ZeroSlice<u32>
sourcepub const fn try_from_bytes(bytes: &[u8]) -> Result<&Self, ZeroVecError>
pub const fn try_from_bytes(bytes: &[u8]) -> Result<&Self, ZeroVecError>
This function can be used for constructing ZeroVecs in a const context, avoiding parsing checks.
This cannot be generic over T because of current limitations in const
, but if
this method is needed in a non-const context, check out ZeroSlice::parse_byte_slice()
instead.
See ZeroSlice::cast()
for an example.
sourcepub const fn from_ule_slice_const(slice: &[RawBytesULE<4>]) -> &Self
pub const fn from_ule_slice_const(slice: &[RawBytesULE<4>]) -> &Self
This function can be used for constructing ZeroVecs in a const context, avoiding parsing checks.
See ZeroSlice
for an example.
sourceimpl ZeroSlice<u64>
impl ZeroSlice<u64>
sourcepub const fn try_from_bytes(bytes: &[u8]) -> Result<&Self, ZeroVecError>
pub const fn try_from_bytes(bytes: &[u8]) -> Result<&Self, ZeroVecError>
This function can be used for constructing ZeroVecs in a const context, avoiding parsing checks.
This cannot be generic over T because of current limitations in const
, but if
this method is needed in a non-const context, check out ZeroSlice::parse_byte_slice()
instead.
See ZeroSlice::cast()
for an example.
sourcepub const fn from_ule_slice_const(slice: &[RawBytesULE<8>]) -> &Self
pub const fn from_ule_slice_const(slice: &[RawBytesULE<8>]) -> &Self
This function can be used for constructing ZeroVecs in a const context, avoiding parsing checks.
See ZeroSlice
for an example.
sourceimpl ZeroSlice<u128>
impl ZeroSlice<u128>
sourcepub const fn try_from_bytes(bytes: &[u8]) -> Result<&Self, ZeroVecError>
pub const fn try_from_bytes(bytes: &[u8]) -> Result<&Self, ZeroVecError>
This function can be used for constructing ZeroVecs in a const context, avoiding parsing checks.
This cannot be generic over T because of current limitations in const
, but if
this method is needed in a non-const context, check out ZeroSlice::parse_byte_slice()
instead.
See ZeroSlice::cast()
for an example.
sourcepub const fn from_ule_slice_const(slice: &[RawBytesULE<16>]) -> &Self
pub const fn from_ule_slice_const(slice: &[RawBytesULE<16>]) -> &Self
This function can be used for constructing ZeroVecs in a const context, avoiding parsing checks.
See ZeroSlice
for an example.
Trait Implementations
sourceimpl<'a, T> BorrowedZeroVecLike<'a, T> for &'a ZeroSlice<T> where
T: AsULE + Copy,
impl<'a, T> BorrowedZeroVecLike<'a, T> for &'a ZeroSlice<T> where
T: AsULE + Copy,
sourcefn zvl_get_borrowed(&self, index: usize) -> Option<&'a T::ULE>
fn zvl_get_borrowed(&self, index: usize) -> Option<&'a T::ULE>
Get element at index
, with a longer lifetime
sourceimpl<T> EncodeAsVarULE<ZeroSlice<T>> for &[T] where
T: AsULE + 'static,
impl<T> EncodeAsVarULE<ZeroSlice<T>> for &[T] where
T: AsULE + 'static,
sourcefn 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
Calls cb
with a piecewise list of byte slices that when concatenated
produce the memory pattern of the corresponding instance of T
. Read more
sourcefn encode_var_ule_len(&self) -> usize
fn encode_var_ule_len(&self) -> usize
Return the length, in bytes, of the corresponding VarULE
type
sourcefn encode_var_ule_write(&self, dst: &mut [u8])
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()
Read more
sourceimpl<T> EncodeAsVarULE<ZeroSlice<T>> for Vec<T> where
T: AsULE + 'static,
impl<T> EncodeAsVarULE<ZeroSlice<T>> for Vec<T> where
T: AsULE + 'static,
sourcefn 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
Calls cb
with a piecewise list of byte slices that when concatenated
produce the memory pattern of the corresponding instance of T
. Read more
sourcefn encode_var_ule_len(&self) -> usize
fn encode_var_ule_len(&self) -> usize
Return the length, in bytes, of the corresponding VarULE
type
sourcefn encode_var_ule_write(&self, dst: &mut [u8])
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()
Read more
sourceimpl<T> EncodeAsVarULE<ZeroSlice<T>> for ZeroVec<'_, T> where
T: AsULE + 'static,
impl<T> EncodeAsVarULE<ZeroSlice<T>> for ZeroVec<'_, T> where
T: AsULE + 'static,
sourcefn 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
Calls cb
with a piecewise list of byte slices that when concatenated
produce the memory pattern of the corresponding instance of T
. Read more
sourcefn encode_var_ule_len(&self) -> usize
fn encode_var_ule_len(&self) -> usize
Return the length, in bytes, of the corresponding VarULE
type
sourcefn encode_var_ule_write(&self, dst: &mut [u8])
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()
Read more
sourceimpl<T: AsULE + Ord> Ord for ZeroSlice<T>
impl<T: AsULE + Ord> Ord for ZeroSlice<T>
sourceimpl<'a, T: AsULE + PartialOrd> PartialOrd<ZeroSlice<T>> for ZeroSlice<T>
impl<'a, T: AsULE + PartialOrd> PartialOrd<ZeroSlice<T>> for ZeroSlice<T>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn 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 more
sourceimpl<T> Serialize for ZeroSlice<T> where
T: Serialize + AsULE,
impl<T> Serialize for ZeroSlice<T> where
T: Serialize + AsULE,
This impl can be made available by enabling the optional serde_serialize
feature of the zerovec
crate
sourceimpl<T: AsULE + 'static> VarULE for ZeroSlice<T>
impl<T: AsULE + 'static> VarULE for ZeroSlice<T>
sourcefn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError>
fn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError>
Validates a byte slice, &[u8]
. Read more
sourceunsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &Self
unsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &Self
Takes a byte slice, &[u8]
, and return it as &Self
with the same lifetime, assuming
that this byte slice has previously been run through Self::parse_byte_slice()
with
success. Read more
sourcefn parse_byte_slice(bytes: &[u8]) -> Result<&Self, ZeroVecError>
fn parse_byte_slice(bytes: &[u8]) -> Result<&Self, ZeroVecError>
Parses a byte slice, &[u8]
, and return it as &Self
with the same lifetime. Read more
sourcefn as_byte_slice(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
fn as_byte_slice(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Given &Self
, returns a &[u8]
with the same lifetime. Read more
sourcefn to_boxed(&self) -> Box<Self>ⓘNotable traits for Box<R, Global>impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
fn to_boxed(&self) -> Box<Self>ⓘNotable traits for Box<R, Global>impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
Allocate on the heap as a Box<T>
sourceimpl<'zf, T> ZeroFrom<'zf, ZeroSlice<T>> for ZeroVec<'zf, T> where
T: 'static + AsULE + ?Sized,
impl<'zf, T> ZeroFrom<'zf, ZeroSlice<T>> for ZeroVec<'zf, T> where
T: 'static + AsULE + ?Sized,
sourceimpl<'a, T: AsULE + 'static> ZeroMapKV<'a> for ZeroSlice<T>
impl<'a, T: AsULE + 'static> ZeroMapKV<'a> for ZeroSlice<T>
type Container = VarZeroVec<'a, ZeroSlice<T>>
type Container = VarZeroVec<'a, ZeroSlice<T>>
The container that can be used with this type: ZeroVec
or VarZeroVec
.
sourceimpl<'a, T> ZeroVecLike<'a, T> for &'a ZeroSlice<T> where
T: AsULE + Copy,
impl<'a, T> ZeroVecLike<'a, T> for &'a ZeroSlice<T> where
T: AsULE + Copy,
type BorrowedVariant = &'a ZeroSlice<T>
type BorrowedVariant = &'a ZeroSlice<T>
A fully borrowed version of this
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. Read more
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. Read more
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. Read more
sourcefn zvl_is_ascending(&self) -> bool where
T: Ord,
fn zvl_is_ascending(&self) -> bool where
T: Ord,
Check if this vector is in ascending order according to T
s Ord
impl
sourcefn zvl_as_borrowed(&'a self) -> &'a ZeroSlice<T>
fn zvl_as_borrowed(&'a self) -> &'a ZeroSlice<T>
Construct a borrowed variant by borrowing from &self
. Read more
sourcefn zvl_as_borrowed_inner(&self) -> Option<&'a ZeroSlice<T>>
fn zvl_as_borrowed_inner(&self) -> Option<&'a ZeroSlice<T>>
Extract the inner borrowed variant if possible. Returns None
if the data is owned. Read more
sourcefn zvl_from_borrowed(b: &'a ZeroSlice<T>) -> Self
fn zvl_from_borrowed(b: &'a ZeroSlice<T>) -> Self
Construct from the borrowed version of the type Read more
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 Read more
sourcefn zvl_is_empty(&self) -> bool
fn zvl_is_empty(&self) -> bool
Check if this vector is empty
impl<T> Eq for ZeroSlice<T> where
T: AsULE + Eq,
Auto Trait Implementations
impl<T> RefUnwindSafe for ZeroSlice<T> where
<T as AsULE>::ULE: RefUnwindSafe,
impl<T> Send for ZeroSlice<T> where
<T as AsULE>::ULE: Send,
impl<T> !Sized for ZeroSlice<T>
impl<T> Sync for ZeroSlice<T> where
<T as AsULE>::ULE: Sync,
impl<T> Unpin for ZeroSlice<T> where
<T as AsULE>::ULE: Unpin,
impl<T> UnwindSafe for ZeroSlice<T> where
<T as AsULE>::ULE: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more