2014-02-05 22:33:10 +00:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-08-19 17:52:07 +00:00
|
|
|
trait IDummy {
|
|
|
|
fn do_nothing(&self);
|
|
|
|
}
|
|
|
|
|
2015-01-28 13:34:18 +00:00
|
|
|
#[derive(Debug)]
|
2013-08-19 17:52:07 +00:00
|
|
|
struct A { a: int }
|
2015-01-28 13:34:18 +00:00
|
|
|
#[derive(Debug)]
|
2013-12-10 07:16:18 +00:00
|
|
|
struct B<'a> { b: int, pa: &'a A }
|
2013-08-19 17:52:07 +00:00
|
|
|
|
|
|
|
impl IDummy for A {
|
|
|
|
fn do_nothing(&self) {
|
2014-01-09 10:06:55 +00:00
|
|
|
println!("A::do_nothing() is called");
|
2013-08-19 17:52:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-10 07:16:18 +00:00
|
|
|
impl<'a> B<'a> {
|
|
|
|
fn get_pa(&self) -> &'a IDummy { self.pa as &'a IDummy }
|
2013-08-19 17:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let sa = A { a: 100 };
|
|
|
|
let sb = B { b: 200, pa: &sa };
|
|
|
|
|
2014-12-20 08:09:35 +00:00
|
|
|
println!("sa is {:?}", sa);
|
|
|
|
println!("sb is {:?}", sb);
|
2013-08-19 17:52:07 +00:00
|
|
|
}
|