[][src]Trait moore::arenas::AllocOwned

pub trait AllocOwned<'a, 't, T> where
    T: 't + ToOwned + ?Sized
{ pub fn alloc_owned(&'a self, value: <T as ToOwned>::Owned) -> &'t T; pub fn maybe_alloc(&'a self, value: Cow<'t, T>) -> &'t T { ... }
pub fn force_alloc(&'a self, value: Cow<'_, T>) -> &'t T { ... } }

Allocates values implementing ToOwned.

This is merely a marker trait that you should not implement yourself. It is implemented automatically on anything that supports Alloc.

Required methods

pub fn alloc_owned(&'a self, value: <T as ToOwned>::Owned) -> &'t T[src]

Allocate a value of type T: ToOwned into this arena.

This function differs from Alloc::alloc in that it takes T::Owned and returns &T.

Loading content...

Provided methods

pub fn maybe_alloc(&'a self, value: Cow<'t, T>) -> &'t T[src]

Conditionally allocate a value of type Cow<T>.

If the value is Cow::Owned, allocates and returns a reference to it; if it is Cow::Borrowed, returns the reference without allocation. This requires that the borrow in Cow has the same lifetime as the allocated reference will have, as indicated by the type Cow<'t, T> -> &'t T. Use force_alloc if you don't have such a lifetime guarantee.

pub fn force_alloc(&'a self, value: Cow<'_, T>) -> &'t T[src]

Forcefully allocate a value of type Cow<T>.

Regardless of whether the value is Cow::Owned or Cow::Borrowed, it is converted to the owned value via ToOwned::into_owned() and allocated. This function is useful if you have no guarantee that the lifetime of the borrow in Cow has the same lifetime as the allocated reference, as indicated by the type Cow<T> -> &'t T'. Use maybe_alloc` if you do have such a lifetime guarantee.

Loading content...

Implementors

impl<'a, 't, T> AllocOwned<'a, 't, T> for dyn Alloc<'a, 't, T> + 'static where
    T: 't + ToOwned<Owned = T>, 
[src]

Loading content...