2012-09-11 19:46:20 -05:00
|
|
|
extern mod std;
|
2012-09-10 14:25:45 -05:00
|
|
|
|
|
|
|
trait Serializer {
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Serializable {
|
|
|
|
fn serialize<S: Serializer>(s: S);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl int: Serializable {
|
|
|
|
fn serialize<S: Serializer>(_s: S) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
struct F<A> { a: A }
|
|
|
|
|
2012-09-10 17:24:42 -05:00
|
|
|
impl<A: Copy Serializable> F<A>: Serializable {
|
2012-09-10 14:25:45 -05:00
|
|
|
fn serialize<S: Serializer>(s: S) {
|
|
|
|
self.a.serialize(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl io::Writer: Serializer {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
do io::with_str_writer |wr| {
|
|
|
|
let foo = F { a: 1 };
|
|
|
|
foo.serialize(wr);
|
|
|
|
|
|
|
|
let bar = F { a: F {a: 1 } };
|
|
|
|
bar.serialize(wr);
|
|
|
|
};
|
|
|
|
}
|