Macro dynstore::impl_castable
source · [−]macro_rules! impl_castable {
{} => { ... };
{
impl Castable for $struct:ident {
$(
into dyn $trait:path;
)*
} $($tail:tt)*
} => { ... };
{
impl Castable into dyn $trait:path {
$(for $struct:path;)*
} $($tail:tt)*
} => { ... };
}
Expand description
Implements Castable
for a struct.
Examples
#[derive(Debug)]
struct Foo;
trait Baz {}
impl Baz for Foo {}
dynstore::impl_castable! {
impl Castable for Foo {
into dyn std::fmt::Debug;
into dyn Baz;
}
}
If the inventory
feature is enabled, you can use another variation of this macro to enable
casting into a new trait for an already-Castable
struct.
pub struct Foo;
pub struct Bar;
pub trait Baz {}
impl Baz for Foo {}
dynstore::impl_castable! {
impl Castable for Foo {
into dyn Baz;
}
impl Castable for Bar {}
}
trait Bing {}
impl Bing for Foo {}
impl Bing for Bar {}
dynstore::impl_castable! {
impl Castable into dyn Bing {
for Foo;
for Bar;
}
}