2013-10-21 03:50:09 -04:00
|
|
|
// Copyright 2013 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.
|
|
|
|
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2015-01-08 02:25:56 +01:00
|
|
|
#![allow(unknown_features)]
|
|
|
|
#![feature(box_syntax)]
|
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);
|
|
|
|
|
2015-02-17 21:41:32 +01:00
|
|
|
let x: Box<_> = box new_x;
|
2013-10-21 03:50:09 -04:00
|
|
|
let new_x = x.change_again();
|
|
|
|
assert_eq!(new_x.a, 45);
|
|
|
|
}
|