Skip to content

Instantly share code, notes, and snippets.

@bvssvni
Last active January 2, 2016 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bvssvni/8241479 to your computer and use it in GitHub Desktop.
Save bvssvni/8241479 to your computer and use it in GitHub Desktop.
fn add<T: Add<T, T>>(
a: proc() -> T,
b: proc() -> T
) -> proc() -> T {
proc() a() + b()
}
fn main() {
let a = proc() 2;
let b = proc() 3;
let c = add(a, b);
let d = c();
println!("{}", d);
let e = c();
println!("{}", e);
}
Compiler error:
/home/sven/Desktop/prob/src/closure/main.rs:15:9: 15:10 error: use of moved value: `c`
/home/sven/Desktop/prob/src/closure/main.rs:15 let e = c();
^
/home/sven/Desktop/prob/src/closure/main.rs:13:9: 13:10 note: `c` moved here because it has type `proc:Send() -> int`, which is non-copyable (perhaps you meant to use clone()?)
/home/sven/Desktop/prob/src/closure/main.rs:13 let d = c();
^
error: aborting due to previous error
task '<unnamed>' failed at 'explicit failure', /home/sven/Desktop/rust/src/libsyntax/diagnostic.rs:102
task '<unnamed>' failed at 'receiving on a closed channel', /home/sven/Desktop/rust/src/libstd/comm/mod.rs:728
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment