2013-08-19 12:52:07 -05:00
|
|
|
trait IDummy {
|
|
|
|
fn do_nothing(&self);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct A { a: int }
|
2013-12-10 01:16:18 -06:00
|
|
|
struct B<'a> { b: int, pa: &'a A }
|
2013-08-19 12:52:07 -05:00
|
|
|
|
|
|
|
impl IDummy for A {
|
|
|
|
fn do_nothing(&self) {
|
|
|
|
println("A::do_nothing() is called");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-10 01:16:18 -06:00
|
|
|
impl<'a> B<'a> {
|
|
|
|
fn get_pa(&self) -> &'a IDummy { self.pa as &'a IDummy }
|
2013-08-19 12:52:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let sa = A { a: 100 };
|
|
|
|
let sb = B { b: 200, pa: &sa };
|
|
|
|
|
2013-10-21 15:08:31 -05:00
|
|
|
debug!("sa is {:?}", sa);
|
|
|
|
debug!("sb is {:?}", sb);
|
|
|
|
debug!("sb.pa is {:?}", sb.get_pa());
|
2013-08-19 12:52:07 -05:00
|
|
|
}
|