Struct emplacable::Emplacable
source · [−]#[repr(transparent)]pub struct Emplacable<T, C>where
T: ?Sized,
C: EmplacableFn<T>,{ /* private fields */ }Expand description
A wrapped closure that you can pass to functions like box_new_with,
that describes how to write a value of type T to a caller-provided
allocation. You can get a T out of an Emplacable through functions like
box_new_with. Alternately, you can drop the value of type T by dropping
the Emplacable. Or you can forget the value of type T with Emplacable::forget.
Implementations
sourceimpl<T, C> Emplacable<T, C>where
T: ?Sized,
C: EmplacableFn<T>,
impl<T, C> Emplacable<T, C>where
T: ?Sized,
C: EmplacableFn<T>,
sourcepub unsafe fn from_closure(closure: C) -> Self
pub unsafe fn from_closure(closure: C) -> Self
Create a new Emplacable from a closure.
This is only useful if you are implementing
a function that returns an unsized value as
an Emplacable.
Safety
The closure closurse must, either diverge
without returning, or, if it returns, then
it must have used the emplacer to fully
initalize the value.
sourcepub fn into_closure(self) -> C
pub fn into_closure(self) -> C
Returns the closure inside this Emplacable.
This is only useful if you are implementing
a function like box_new_with.
sourcepub fn forget(self)
pub fn forget(self)
Runs the Emplacable closure,
but doesn’t run the “inner closure”,
so the value of type T is forgotten,
and its destrutor is not run.
If you want to drop the T and run its destructor,
drop the Emplacable instead.
sourcepub fn unsize<U: ?Sized>(self) -> Emplacable<U, impl EmplacableFn<U>>where
T: Sized + Unsize<U>,
pub fn unsize<U: ?Sized>(self) -> Emplacable<U, impl EmplacableFn<U>>where
T: Sized + Unsize<U>,
Turns an emplacer for a sized type into one for an unsized type via an unsizing coercion (for example, array -> slice or concrete type -> trait object).
sourcepub fn from_iter<I>(iter: I) -> Emplacable<[T], impl EmplacableFn<[T]>>where
T: Sized,
I: IntoIterator<Item = Self>,
I::IntoIter: ExactSizeIterator,
pub fn from_iter<I>(iter: I) -> Emplacable<[T], impl EmplacableFn<[T]>>where
T: Sized,
I: IntoIterator<Item = Self>,
I::IntoIter: ExactSizeIterator,
Creates an Emplacable for a slice of values of type T out of an iterator
of values of type T.
This function differs from FromIterator::from_iter in that the iterator is required to
be an ExactSizeIterator. If ExactSizeIterator is incorrectly implemented,
this function may panic or otherwise misbehave (but will not trigger UB).
sourceimpl<T, C> Emplacable<[T], C>where
C: EmplacableFn<[T]>,
impl<T, C> Emplacable<[T], C>where
C: EmplacableFn<[T]>,
sourceimpl<C> Emplacable<str, C>where
C: EmplacableFn<str>,
impl<C> Emplacable<str, C>where
C: EmplacableFn<str>,
sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Turns this emplacer for a string slice into an owned, heap-allocated String.
Trait Implementations
sourceimpl<T, C> Drop for Emplacable<T, C>where
T: ?Sized,
C: EmplacableFn<T>,
impl<T, C> Drop for Emplacable<T, C>where
T: ?Sized,
C: EmplacableFn<T>,
sourceimpl<T, C> Extend<Emplacable<T, C>> for Vec<T>where
C: EmplacableFn<T>,
impl<T, C> Extend<Emplacable<T, C>> for Vec<T>where
C: EmplacableFn<T>,
sourcefn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Emplacable<T, C>>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Emplacable<T, C>>,
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)