2012-12-11 01:32:48 +00:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
2014-05-22 18:28:01 +00:00
|
|
|
extern crate debug;
|
2014-05-06 01:56:44 +00:00
|
|
|
|
2012-12-07 02:32:13 +00:00
|
|
|
trait T {
|
|
|
|
fn print(&self);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S {
|
|
|
|
s: int,
|
|
|
|
}
|
|
|
|
|
2013-02-14 19:47:00 +00:00
|
|
|
impl T for S {
|
2012-12-07 02:32:13 +00:00
|
|
|
fn print(&self) {
|
2013-09-25 05:16:43 +00:00
|
|
|
println!("{:?}", self);
|
2012-12-07 02:32:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn print_t(t: &T) {
|
|
|
|
t.print();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn print_s(s: &S) {
|
|
|
|
s.print();
|
|
|
|
}
|
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2014-05-06 01:56:44 +00:00
|
|
|
let s: Box<S> = box S { s: 5 };
|
2014-07-07 23:35:15 +00:00
|
|
|
print_s(&*s);
|
2014-05-06 01:56:44 +00:00
|
|
|
let t: Box<T> = s as Box<T>;
|
2012-12-07 02:32:13 +00:00
|
|
|
print_t(t);
|
|
|
|
}
|