Macro emplacable::unsize
source · macro_rules! unsize { ($e:expr, ($src:ty) -> $dst:ty) => { ... }; }
Expand description
Helper for coercing values to unsized types.
The unsized_fn_params
has some rough edges when it comes to coercing
sized values to unsized ones by value. This macro works around that.
If you have a value val
of type SizedType
, and you want to coerce it
to UnsizedType
, write unsize!(val, (SizedType) -> UnsizedType))
.
Probably useless without the unsized_fn_params
or unsized_locals
nightly features.
Requires the alloc
crate feature
(though doesn’t actually allocate on the heap).
§Example
#![feature(unsized_fn_params)]
use core::fmt::Debug;
use emplacable::{box_new, unsize};
let mut my_box: Box<dyn Debug> = box_new(unsize!("hello world!", (&str) -> dyn Debug));
dbg!(&my_box);