mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
22 lines
324 B
Rust
22 lines
324 B
Rust
//@ check-pass
|
|
|
|
use std::ops::Deref;
|
|
|
|
trait MyTrait {
|
|
fn do_something(&self);
|
|
fn as_str(&self) -> &str;
|
|
}
|
|
|
|
impl Deref for dyn MyTrait {
|
|
type Target = str;
|
|
fn deref(&self) -> &Self::Target {
|
|
self.as_str()
|
|
}
|
|
}
|
|
|
|
fn trait_object_does_something(t: &dyn MyTrait) {
|
|
t.do_something()
|
|
}
|
|
|
|
fn main() {}
|