Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(unboxed_closures, fn_traits)]
- struct SelfFunc {
- sum: i32,
- }
- impl FnOnce<(i32, i32)> for SelfFunc {
- type Output = SelfFunc;
- extern "rust-call" fn call_once(mut self, args: (i32, i32)) -> Self::Output {
- println!("Adding {}", args.0);
- self.sum += args.0;
- self
- }
- }
- impl FnOnce<()> for SelfFunc {
- type Output = i32;
- extern "rust-call" fn call_once(self, _args: ()) -> Self::Output {
- println!("Finished adding");
- self.sum
- }
- }
- fn main() {
- let f = SelfFunc { sum: 0 };
- let a = (1, 2);
- let sum = f(1, 0)(2, 0)(3, 0)();
- println!("Sum = {}", sum)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement