pub trait AllocOwned<'a, 't, T: ToOwned + ?Sized + 't> {
    fn alloc_owned(&'a self, value: <T as ToOwned>::Owned) -> &'t T;

    fn maybe_alloc(&'a self, value: Cow<'t, T>) -> &'t T { ... }
fn force_alloc(&'a self, value: Cow<'_, T>) -> &'t T { ... } }
Expand description

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

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.

Provided methods

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.

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.

Implementors