Skip to main content

Emplace

Trait Emplace 

Source
pub trait Emplace<T>: Sized + Deref {
    type Output: Deref<Target = Self::Target>;

    // Required method
    fn try_emplace<N>(n: N) -> Result<Self::Output, <N as TryNew>::Error>
       where N: TryNew<Output = T>;

    // Provided method
    fn emplace<N>(n: N) -> Self::Output
       where N: New<Output = T> { ... }
}
Expand description

A pointer type that may be “emplaced” as a stable address which a New may be used to construct a value with.

The Emplace<T>::Output type is usually either Self or Pin<Self> depending on the API of Self with respect to [DerefMut].

For example, Arc<T>, Box<T>, and Rc<T> are all Emplace<T, Output = Pin<Self>>.

However, cxx::UniquePtr<T>: Emplace<T, Output = Self>, since cxx::UniquePtr<T> already only allows obtaining pinned mutable references to T due to its more restrictive API, and hence cxx::UniquePtr<T> does not need to be pinned itself.

Required Associated Types§

Source

type Output: Deref<Target = Self::Target>

The stable address type within which a value of type T is emplaced.

Required Methods§

Source

fn try_emplace<N>(n: N) -> Result<Self::Output, <N as TryNew>::Error>
where N: TryNew<Output = T>,

Constructs a new smart pointer and tries to emplace n into its storage.

Provided Methods§

Source

fn emplace<N>(n: N) -> Self::Output
where N: New<Output = T>,

Constructs a new smart pointer and emplaces n into its storage.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T> Emplace<T> for Arc<T>

Source§

type Output = Pin<Arc<T>>

Source§

fn try_emplace<N>( n: N, ) -> Result<<Arc<T> as Emplace<T>>::Output, <N as TryNew>::Error>
where N: TryNew<Output = T>,

Source§

impl<T> Emplace<T> for Box<T>

Source§

type Output = Pin<Box<T>>

Source§

fn try_emplace<N>( n: N, ) -> Result<<Box<T> as Emplace<T>>::Output, <N as TryNew>::Error>
where N: TryNew<Output = T>,

Source§

impl<T> Emplace<T> for Rc<T>

Source§

type Output = Pin<Rc<T>>

Source§

fn try_emplace<N>( n: N, ) -> Result<<Rc<T> as Emplace<T>>::Output, <N as TryNew>::Error>
where N: TryNew<Output = T>,

Implementors§