2012-09-17 13:00:50 -05:00
|
|
|
trait Pushable<T> {
|
|
|
|
fn push_val(&mut self, +t: T);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> ~[T]: Pushable<T> {
|
|
|
|
fn push_val(&mut self, +t: T) {
|
2012-09-19 00:45:24 -05:00
|
|
|
self.push(move t);
|
2012-09-17 13:00:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut v = ~[1];
|
|
|
|
v.push_val(2);
|
|
|
|
v.push_val(3);
|
|
|
|
assert v == ~[1, 2, 3];
|
|
|
|
}
|