| Crates.io | match_any_trait |
| lib.rs | match_any_trait |
| version | 0.1.1 |
| created_at | 2023-09-14 08:52:56.736118+00 |
| updated_at | 2023-09-14 14:25:31.585921+00 |
| description | match expressions for any trait |
| homepage | |
| repository | https://github.com/mingshuisheng/match_any_trait |
| max_upload_size | |
| id | 972431 |
| size | 18,790 |
Provides a procedural macro, that is match expressions for any trait
cargo add match_any_trait
Example
use std::any::Any;
use match_any_trait::match_any_trait;
#[derive(Debug)]
struct MyStruct {
x: u32,
}
#[derive(Debug)]
struct MyNum {
y: u32,
}
#[derive(Debug)]
struct MyTuple;
#[derive(Debug)]
struct MyTemplate;
fn main() {
// let num = MyStruct{
// x: 1,
// };
// let num = MyNum{
// y: 1,
// };
// let num = MyTuple;
let num = MyTemplate;
let num = &num as &dyn Any;
match_any_trait! {
match num {
MyStruct(s) | MyNum(s) => println!("num is a {:?}", s),
MyTuple => println!("num is a MyTuple")
MyTemplate => println!("num is a MyTemplate"),
_ => println!("num is unknown"),
}
}
}