2019-09-01 16:30:19 -05:00
|
|
|
// check-pass
|
2019-06-21 01:18:00 -05:00
|
|
|
|
|
|
|
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() {}
|