2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
2014-05-05 18:56:44 -07:00
|
|
|
|
2013-10-21 03:50:09 -04:00
|
|
|
struct X {
|
2015-03-25 17:06:52 -07:00
|
|
|
a: isize
|
2013-10-21 03:50:09 -04:00
|
|
|
}
|
|
|
|
|
2014-12-19 06:54:09 -05:00
|
|
|
trait Changer : Sized {
|
2013-10-21 03:50:09 -04:00
|
|
|
fn change(mut self) -> Self {
|
|
|
|
self.set_to(55);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2014-07-07 23:19:35 -07:00
|
|
|
fn change_again(mut self: Box<Self>) -> Box<Self> {
|
2013-10-21 03:50:09 -04:00
|
|
|
self.set_to(45);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
fn set_to(&mut self, a: isize);
|
2013-10-21 03:50:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Changer for X {
|
2015-03-25 17:06:52 -07:00
|
|
|
fn set_to(&mut self, a: isize) {
|
2013-10-21 03:50:09 -04:00
|
|
|
self.a = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let x = X { a: 32 };
|
|
|
|
let new_x = x.change();
|
|
|
|
assert_eq!(new_x.a, 55);
|
|
|
|
|
2021-08-25 02:39:40 +02:00
|
|
|
let x: Box<_> = Box::new(new_x);
|
2013-10-21 03:50:09 -04:00
|
|
|
let new_x = x.change_again();
|
|
|
|
assert_eq!(new_x.a, 45);
|
|
|
|
}
|