Skip to content

Instantly share code, notes, and snippets.

Created November 3, 2015 06:52
Show Gist options
  • Save anonymous/dad75ccaeb5e637c8199 to your computer and use it in GitHub Desktop.
Save anonymous/dad75ccaeb5e637c8199 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
#[cfg(test)]
mod tests {
use std::rc::Rc;
// the `type` is not needed but it makes it easier if you will
// be using it in other function declarations.
type Adder = Fn(i32) -> i32;
fn sum(x: Rc<i32>) -> Rc<Adder> {
Rc::new(move |n: i32| *x + n)
}
#[test]
fn it_works() {
let foo = sum(Rc::new(2));
assert_eq!(5, foo(3));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment