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