Struct zerovec::VarZeroCow
source · 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_byte_slice(bytes: &'a [u8]) -> Result<Self, UleError>
pub fn parse_byte_slice(bytes: &'a [u8]) -> Result<Self, UleError>
Construct from a slice. Errors if the slice doesn’t represent a valid V
sourcepub fn parse_owned_byte_slice(bytes: Box<[u8]>) -> Result<Self, UleError>
pub fn parse_owned_byte_slice(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_byte_slice_unchecked(bytes: &'a [u8]) -> Self
pub const unsafe fn from_byte_slice_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_byte_slice()
or V::validate_byte_slice()
.
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: VarULE + ?Sized> Bake for VarZeroCow<'a, V>
impl<'a, V: VarULE + ?Sized> Bake for VarZeroCow<'a, V>
source§fn bake(&self, env: &CrateEnv) -> TokenStream
fn bake(&self, env: &CrateEnv) -> TokenStream
source§impl<'a, V: VarULE + ?Sized> BakeSize for VarZeroCow<'a, V>
impl<'a, V: VarULE + ?Sized> BakeSize for VarZeroCow<'a, V>
source§fn borrows_size(&self) -> usize
fn borrows_size(&self) -> usize
source§impl<'a, V: ?Sized> Clone for VarZeroCow<'a, V>
impl<'a, V: ?Sized> Clone for VarZeroCow<'a, V>
source§impl<'a, 'de: 'a, V: VarULE + ?Sized> Deserialize<'de> for VarZeroCow<'a, V>where
Box<V>: Deserialize<'de>,
impl<'a, 'de: 'a, V: VarULE + ?Sized> Deserialize<'de> for VarZeroCow<'a, V>where
Box<V>: Deserialize<'de>,
source§fn deserialize<Des>(deserializer: Des) -> Result<Self, Des::Error>where
Des: Deserializer<'de>,
fn deserialize<Des>(deserializer: Des) -> Result<Self, Des::Error>where
Des: Deserializer<'de>,
source§impl<'a, V: ?Sized> Drop for VarZeroCow<'a, V>
impl<'a, V: ?Sized> Drop 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, V: VarULE + ?Sized> ZeroFrom<'a, V> for VarZeroCow<'a, V>
impl<'a, V: VarULE + ?Sized> ZeroFrom<'a, V> for VarZeroCow<'a, V>
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>
impl<'a, V: ?Sized> Send for VarZeroCow<'a, V>
impl<'a, V: ?Sized> Sync 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> 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,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)