A box that stores types like pointers,
forgetting everything besides Self: Unsize<dyn Trait>
```rust use dyn_ptr::{Dyn, PointerLike};
fn impl(: impl fmt::Display) {}
fn dyn_(x: Dyn
impl(12); impl(12usize); impl(Box::new(12));
dyn((&12).dodyn()); // ref to i32
is repr as PtrRepr
dyn(12usize.dodyn()); // usize
is repr as PtrRepr
dyn(Box::new(12).do_dyn()); // usize
is repr as PtrRepr
``
Instead of
const dynand
mut dynfat pointers, that fat pointer store dtor and works like
Box`.\
And accept by value (instead of ref/ptr)
This can be used for example in async traits, in which you cannot use Box<dyn Future>
, because core
has no allocators.
Dyn
can help erase type about store (for example Pin<Box>
)
``rust
// possible desugared for
async fn in dyn traits
trait Async<'a> {
// original:
async asyncfn() -> &'a ();`
fn asyncfn
// select: dyn
or impl
context
struct DynCtx;
struct ImplCtx;
trait Ctx<'a> { type ImplFuture: Future