pub struct VarZeroCow<'a, V: ?Sized> { /* private fields */ }
Expand description
Copy-on-write type that efficiently represents VarULE
types as their bitstream representation.
The primary use case for VarULE
types is the ability to store complex variable-length datastructures
inside variable-length collections like crate::VarZeroVec
.
Underlying this ability is the fact that VarULE
types can be efficiently represented as a flat
bytestream.
In zero-copy cases, sometimes one wishes to unconditionally use this bytestream representation, for example
to save stack size. A struct with five Cow<'a, str>
s is not as stack-efficient as a single Cow
containing
the bytestream representation of, say, Tuple5VarULE<str, str, str, str, str>
.
This type helps in this case: It is logically a Cow<'a, V>
, with some optimizations, that is guaranteed
to serialize as a byte stream in machine-readable scenarios.
During human-readable serialization, it will fall back to the serde impls on V
, which ought to have
a human-readable variant.
Implementations§
Source§impl<'a, V: VarULE + ?Sized> VarZeroCow<'a, V>
impl<'a, V: VarULE + ?Sized> VarZeroCow<'a, V>
Sourcepub fn parse_bytes(bytes: &'a [u8]) -> Result<Self, UleError>
pub fn parse_bytes(bytes: &'a [u8]) -> Result<Self, UleError>
Construct from a slice. Errors if the slice doesn’t represent a valid V
Sourcepub fn parse_owned_bytes(bytes: Box<[u8]>) -> Result<Self, UleError>
pub fn parse_owned_bytes(bytes: Box<[u8]>) -> Result<Self, UleError>
Construct from an owned slice. Errors if the slice doesn’t represent a valid V
Sourcepub const unsafe fn from_bytes_unchecked(bytes: &'a [u8]) -> Self
pub const unsafe fn from_bytes_unchecked(bytes: &'a [u8]) -> Self
Construct from a slice that is known to represent a valid V
§Safety
bytes
must be a valid V
, i.e. it must successfully pass through
V::parse_bytes()
or V::validate_bytes()
.
Sourcepub fn from_encodeable<E: EncodeAsVarULE<V>>(encodeable: &E) -> Self
pub fn from_encodeable<E: EncodeAsVarULE<V>>(encodeable: &E) -> Self
Construct this from an EncodeAsVarULE
version of the contained type
Will always construct an owned version
Sourcepub fn new_borrowed(val: &'a V) -> Self
pub fn new_borrowed(val: &'a V) -> Self
Construct a new borrowed version of this
Trait Implementations§
Source§impl<'a, V: ?Sized> Clone for VarZeroCow<'a, V>
impl<'a, V: ?Sized> Clone for VarZeroCow<'a, V>
Source§impl<'a, V: VarULE + ?Sized> EncodeAsVarULE<V> for VarZeroCow<'a, V>
impl<'a, V: VarULE + ?Sized> EncodeAsVarULE<V> for VarZeroCow<'a, V>
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, V: VarULE + ?Sized + Ord> Ord for VarZeroCow<'a, V>
impl<'a, V: VarULE + ?Sized + Ord> Ord for VarZeroCow<'a, V>
Source§impl<'a, V: VarULE + ?Sized + PartialOrd> PartialOrd for VarZeroCow<'a, V>
impl<'a, V: VarULE + ?Sized + PartialOrd> PartialOrd for VarZeroCow<'a, V>
Source§impl<'a, T: 'static + ?Sized> Yokeable<'a> for VarZeroCow<'static, T>
This impl requires enabling the optional yoke
Cargo feature of the zerovec
crate
impl<'a, T: 'static + ?Sized> Yokeable<'a> for VarZeroCow<'static, T>
This impl requires enabling the optional yoke
Cargo feature of the zerovec
crate
Source§type Output = VarZeroCow<'a, T>
type Output = VarZeroCow<'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<'a, 'b, V: VarULE + ?Sized> ZeroFrom<'a, VarZeroCow<'b, V>> for VarZeroCow<'a, V>
impl<'a, 'b, V: VarULE + ?Sized> ZeroFrom<'a, VarZeroCow<'b, V>> for VarZeroCow<'a, V>
Source§fn zero_from(other: &'a VarZeroCow<'b, V>) -> Self
fn zero_from(other: &'a VarZeroCow<'b, V>) -> Self
C
into a struct that may retain references into C
.impl<'a, V: VarULE + ?Sized + Eq> Eq for VarZeroCow<'a, V>
Auto Trait Implementations§
impl<'a, V> Freeze for VarZeroCow<'a, V>where
V: ?Sized,
impl<'a, V> RefUnwindSafe for VarZeroCow<'a, V>where
V: RefUnwindSafe + ?Sized,
impl<'a, V> Send for VarZeroCow<'a, V>
impl<'a, V> Sync for VarZeroCow<'a, V>
impl<'a, V> Unpin for VarZeroCow<'a, V>where
V: ?Sized,
impl<'a, V> UnwindSafe for VarZeroCow<'a, V>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 24 bytes