[][src]Trait beef::Beef

pub unsafe trait Beef: ToOwned {
    fn capacity(owned: &Self::Owned) -> Option<NonZeroUsize>;
unsafe fn owned_ptr(owned: &mut Self::Owned) -> NonNull<Self>;
unsafe fn rebuild(ptr: NonNull<Self>, capacity: usize) -> Self::Owned; }

Helper trait required by Cow<T> to extract capacity of owned variant of T, and manage conversions.

This can be only implemented on types that match requirements:

  • T::Owned has a capacity, which is an extra word that is absent in T.
  • T::Owned with capacity of 0 does not allocate memory.
  • T::Owned can be reconstructed from *mut T borrowed out of it, plus capacity.

Required methods

fn capacity(owned: &Self::Owned) -> Option<NonZeroUsize>

Get capacity of owned variant of T. Return None for 0. Returning invalid capacity will lead to undefined behavior.

unsafe fn owned_ptr(owned: &mut Self::Owned) -> NonNull<Self>

Convert &mut T::Owned to *mut T, stripping capacity.

unsafe fn rebuild(ptr: NonNull<Self>, capacity: usize) -> Self::Owned

Rebuild T::Owned from NonNull<T> and capacity. This can be done by the likes of Vec::from_raw_parts.

Loading content...

Implementors

impl Beef for str[src]

impl<T: Clone> Beef for [T][src]

Loading content...