Skip to content

Instantly share code, notes, and snippets.

@stivenson
Last active July 3, 2019 17:29
Show Gist options
  • Save stivenson/8a6d5f3d06d08ad2cb55d84bfa3079bc to your computer and use it in GitHub Desktop.
Save stivenson/8a6d5f3d06d08ad2cb55d84bfa3079bc to your computer and use it in GitHub Desktop.
Basic example of closure with a heavy logic
let result = |word| {
// Heavy logic //
let fname = "text_to_find.txt";
// Contents of file
let contents = fs::read_to_string(fname).expect("Something went wrong reading the file");
// Search a word into file's content
match contents.find(word) {
Some(v) => v as u64,
None => 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment