mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 14:16:47 +00:00
28 lines
417 B
Rust
28 lines
417 B
Rust
use intertrait::cast::*;
|
|
use intertrait::*;
|
|
|
|
#[cast_to(Greet)]
|
|
struct Data;
|
|
|
|
trait Source: CastFrom {}
|
|
|
|
trait Greet {
|
|
fn greet(&self);
|
|
}
|
|
|
|
impl Greet for Data {
|
|
fn greet(&self) {
|
|
println!("Hello");
|
|
}
|
|
}
|
|
|
|
impl Source for Data {}
|
|
|
|
#[test]
|
|
fn test_cast_to_on_struct() {
|
|
let data = Data;
|
|
let source: &dyn Source = &data;
|
|
let greet = source.cast::<dyn Greet>();
|
|
greet.unwrap().greet();
|
|
}
|