Last active
July 3, 2019 17:29
-
-
Save stivenson/8a6d5f3d06d08ad2cb55d84bfa3079bc to your computer and use it in GitHub Desktop.
Basic example of closure with a heavy logic
This file contains 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
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