2019-07-27 00:54:25 +03:00
|
|
|
// run-pass
|
2013-08-11 13:58:48 -04:00
|
|
|
// Test invoked `&self` methods on owned objects where the values
|
2014-05-05 18:56:44 -07:00
|
|
|
// closed over contain managed values. This implies that the boxes
|
2013-08-11 13:58:48 -04:00
|
|
|
// will have headers that must be skipped over.
|
|
|
|
|
2013-06-22 09:37:40 +02:00
|
|
|
trait FooTrait {
|
2015-03-25 17:06:52 -07:00
|
|
|
fn foo(self: Box<Self>) -> usize;
|
2013-06-22 09:37:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct BarStruct {
|
2015-03-25 17:06:52 -07:00
|
|
|
x: usize
|
2013-06-22 09:37:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FooTrait for BarStruct {
|
2015-03-25 17:06:52 -07:00
|
|
|
fn foo(self: Box<BarStruct>) -> usize {
|
2013-06-22 09:37:40 +02:00
|
|
|
self.x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2021-08-25 02:39:40 +02:00
|
|
|
let foo = Box::new(BarStruct{ x: 22 }) as Box<dyn FooTrait>;
|
2013-08-11 13:58:48 -04:00
|
|
|
assert_eq!(22, foo.foo());
|
2013-06-22 09:37:40 +02:00
|
|
|
}
|