Struct CoercionInitializer

Source
pub struct CoercionInitializer<T: Unsize<U>, U: ?Sized> { /* private fields */ }
Expand description

An Emplace Initializer for dyn or [T] types, created by concrete type T or [T;N]. For example usize is sized type and implemented Debug:

 use std::fmt::Debug;
 use dst_init::{BoxExt, CoercionInitializer};

 let init:CoercionInitializer<usize,dyn Debug> = CoercionInitializer::new(1usize);
 let boxed:Box<dyn Debug> = Box::emplace(init);
 assert_eq!(format!("{:?}",boxed),"1")

Implementations§

Source§

impl<T: Unsize<U>, U: ?Sized> CoercionInitializer<T, U>

Source

pub fn new(t: T) -> Self

Source

pub fn fallback(self) -> T

Trait Implementations§

Source§

impl<T: Unsize<U>, U: ?Sized> EmplaceInitializer for CoercionInitializer<T, U>

Source§

type Output = U

Source§

fn layout(&mut self) -> Layout

Layout of the type
Source§

fn emplace(self, ptr: NonNull<u8>) -> NonNull<Self::Output>

Emplace the type in given memory

Auto Trait Implementations§

§

impl<T, U> Freeze for CoercionInitializer<T, U>
where T: Freeze, U: ?Sized,

§

impl<T, U> RefUnwindSafe for CoercionInitializer<T, U>

§

impl<T, U> Send for CoercionInitializer<T, U>
where T: Send, U: Send + ?Sized,

§

impl<T, U> Sync for CoercionInitializer<T, U>
where T: Sync, U: Sync + ?Sized,

§

impl<T, U> Unpin for CoercionInitializer<T, U>
where T: Unpin, U: Unpin + ?Sized,

§

impl<T, U> UnwindSafe for CoercionInitializer<T, U>
where T: UnwindSafe, U: UnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.