2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2015-12-03 01:31:49 +00:00
|
|
|
#![feature(unboxed_closures, fn_traits)]
|
2014-06-01 23:35:01 +00:00
|
|
|
|
2015-03-28 09:23:20 +00:00
|
|
|
use std::ops::FnMut;
|
2014-06-01 23:35:01 +00:00
|
|
|
|
|
|
|
struct S {
|
2015-01-12 15:27:25 +00:00
|
|
|
x: i32,
|
|
|
|
y: i32,
|
2014-06-01 23:35:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 15:27:25 +00:00
|
|
|
impl FnMut<()> for S {
|
|
|
|
extern "rust-call" fn call_mut(&mut self, (): ()) -> i32 {
|
2014-06-01 23:35:01 +00:00
|
|
|
self.x * self.y
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-11 14:08:33 +00:00
|
|
|
impl FnOnce<()> for S {
|
|
|
|
type Output = i32;
|
|
|
|
extern "rust-call" fn call_once(mut self, args: ()) -> i32 { self.call_mut(args) }
|
|
|
|
}
|
|
|
|
|
2014-06-01 23:35:01 +00:00
|
|
|
fn main() {
|
|
|
|
let mut s = S {
|
|
|
|
x: 3,
|
|
|
|
y: 3,
|
|
|
|
};
|
|
|
|
let ans = s();
|
|
|
|
assert_eq!(ans, 9);
|
|
|
|
}
|