Struct VarZeroCow

struct VarZeroCow<'a, V: ?Sized> { ... }

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

impl<'a, V: ?Sized> VarZeroCow<'a, V>

fn is_owned(self: &Self) -> bool

Whether or not this is owned

fn as_bytes(self: &Self) -> &[u8]

Get the byte representation of this type

Is also always a valid V and can be passed to V::from_bytes_unchecked()

impl<'a, V: VarULE + ?Sized> VarZeroCow<'a, V>

fn parse_bytes(bytes: &'a [u8]) -> Result<Self, UleError>

Construct from a slice. Errors if the slice doesn't represent a valid V

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

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

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

fn new_borrowed(val: &'a V) -> Self

Construct a new borrowed version of this

fn new_owned(val: Box<V>) -> Self

Construct a new borrowed version of this

impl<'a, 'b, V: VarULE + ?Sized> ZeroFrom for VarZeroCow<'a, V>

fn zero_from(other: &'a VarZeroCow<'b, V>) -> Self

impl<'a, T: 'static + ?Sized> Yokeable for VarZeroCow<'static, T>

fn transform(self: &'a Self) -> &'a <Self as >::Output
fn transform_owned(self: Self) -> <Self as >::Output
unsafe fn make(from: <Self as >::Output) -> Self
fn transform_mut<F>(self: &'a mut Self, f: F)
where
    F: 'static + for<'b> FnOnce(&'b mut <Self as >::Output)

impl<'a, V> Freeze for VarZeroCow<'a, V>

impl<'a, V> RefUnwindSafe for VarZeroCow<'a, V>

impl<'a, V> Send for VarZeroCow<'a, V>

impl<'a, V> Sync for VarZeroCow<'a, V>

impl<'a, V> Unpin for VarZeroCow<'a, V>

impl<'a, V> UnsafeUnpin for VarZeroCow<'a, V>

impl<'a, V> UnwindSafe for VarZeroCow<'a, V>

impl<'a, V: ?Sized> Clone for VarZeroCow<'a, V>

fn clone(self: &Self) -> Self

impl<'a, V: VarULE + ?Sized + Eq> Eq for VarZeroCow<'a, V>

impl<'a, V: VarULE + ?Sized + Ord> Ord for VarZeroCow<'a, V>

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

impl<'a, V: VarULE + ?Sized + PartialEq> PartialEq for VarZeroCow<'a, V>

fn eq(self: &Self, other: &Self) -> bool

impl<'a, V: VarULE + ?Sized + PartialOrd> PartialOrd for VarZeroCow<'a, V>

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

impl<'a, V: VarULE + ?Sized + fmt::Debug> Debug for VarZeroCow<'a, V>

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

impl<'a, V: VarULE + ?Sized> Deref for VarZeroCow<'a, V>

fn deref(self: &Self) -> &V

impl<'a, V: VarULE + ?Sized> EncodeAsVarULE for VarZeroCow<'a, V>

fn encode_var_ule_as_slices<R, impl FnOnce(&[&[u8]]) -> R: FnOnce(&[&[u8]]) -> R>(self: &Self, _: impl FnOnce(&[&[u8]]) -> R) -> R
fn encode_var_ule_len(self: &Self) -> usize
fn encode_var_ule_write(self: &Self, dst: &mut [u8])

impl<'a, V: VarULE + ?Sized> From for VarZeroCow<'a, V>

fn from(other: Box<V>) -> Self

impl<'a, V: VarULE + ?Sized> From for VarZeroCow<'a, V>

fn from(other: &'a V) -> Self

impl<'a, V: VarULE + ?Sized> ZeroFrom for VarZeroCow<'a, V>

fn zero_from(other: &'a V) -> Self

impl<P, T> Receiver for VarZeroCow<'a, V>

impl<T> Any for VarZeroCow<'a, V>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for VarZeroCow<'a, V>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for VarZeroCow<'a, V>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for VarZeroCow<'a, V>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> ErasedDestructor for VarZeroCow<'a, V>

impl<T> From for VarZeroCow<'a, V>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for VarZeroCow<'a, V>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for VarZeroCow<'a, V>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for VarZeroCow<'a, V>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for VarZeroCow<'a, V>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>