-
-
Save JoeyEremondi/e33f99a82bad2a74a186 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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