[−][src]Trait beef::Beef
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 acapacity
, which is an extra word that is absent inT
.T::Owned
withcapacity
of0
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
.