2024-02-16 20:02:50 +00:00
|
|
|
//@ run-pass
|
2014-05-06 01:56:44 +00:00
|
|
|
|
2013-10-21 07:50:09 +00:00
|
|
|
struct X {
|
2015-03-26 00:06:52 +00:00
|
|
|
a: isize
|
2013-10-21 07:50:09 +00:00
|
|
|
}
|
|
|
|
|
2014-12-19 11:54:09 +00:00
|
|
|
trait Changer : Sized {
|
2013-10-21 07:50:09 +00:00
|
|
|
fn change(mut self) -> Self {
|
|
|
|
self.set_to(55);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2014-07-08 06:19:35 +00:00
|
|
|
fn change_again(mut self: Box<Self>) -> Box<Self> {
|
2013-10-21 07:50:09 +00:00
|
|
|
self.set_to(45);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn set_to(&mut self, a: isize);
|
2013-10-21 07:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Changer for X {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn set_to(&mut self, a: isize) {
|
2013-10-21 07:50:09 +00: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 00:39:40 +00:00
|
|
|
let x: Box<_> = Box::new(new_x);
|
2013-10-21 07:50:09 +00:00
|
|
|
let new_x = x.change_again();
|
|
|
|
assert_eq!(new_x.a, 45);
|
|
|
|
}
|