mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-19 09:06:32 +00:00
27
kernel/crates/intertrait/tests/ui/unknown-flag.rs
Normal file
27
kernel/crates/intertrait/tests/ui/unknown-flag.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use intertrait::cast::*;
|
||||
use intertrait::*;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cast_to([sync, send] Greet)]
|
||||
struct Data;
|
||||
|
||||
trait Source: CastFromSync {}
|
||||
|
||||
trait Greet {
|
||||
fn greet(&self);
|
||||
}
|
||||
|
||||
impl Greet for Data {
|
||||
fn greet(&self) {
|
||||
println!("Hello");
|
||||
}
|
||||
}
|
||||
|
||||
impl Source for Data {}
|
||||
|
||||
fn main() {
|
||||
let data = Arc::new(Data);
|
||||
let source: Arc<dyn Source> = data;
|
||||
let greet = source.cast::<dyn Greet>();
|
||||
greet.unwrap_or_else(|_| panic!("can't happen")).greet();
|
||||
}
|
Reference in New Issue
Block a user