castable_to!() { /* proc-macro */ }
Expand description
Declares target traits for casting implemented by a type.
This macro is for registering both a concrete type and its traits to be targets for casting. Useful when the type definition and the trait implementations are in an external crate.
Note: this macro cannot be used in an expression or statement prior to Rust 1.45.0, due to a previous limitation. If you want to use it in an expression or statement, use Rust 1.45.0 or later.
ยงExamples
use intertrait::*;
#[derive(std::fmt::Debug)]
enum Data {
A, B, C
}
trait Greet {
fn greet(&self);
}
impl Greet for Data {
fn greet(&self) {
println!("Hello");
}
}
castable_to! { Data => std::fmt::Debug, Greet }
When the type is Sync + Send
and is used with Arc
:
use intertrait::*;
#[derive(std::fmt::Debug)]
enum Data {
A, B, C
}
trait Greet {
fn greet(&self);
}
impl Greet for Data {
fn greet(&self) {
println!("Hello");
}
}
castable_to! { Data => [sync] std::fmt::Debug, Greet }