Skip to content

Instantly share code, notes, and snippets.

@mre
Created October 14, 2017 16:13
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 mre/b44c7cfa63f9d8ca4258a3a27480d532 to your computer and use it in GitHub Desktop.
Save mre/b44c7cfa63f9d8ca4258a3a27480d532 to your computer and use it in GitHub Desktop.
Print all words containing "rust"
use std::fs::File;
use std::io::{BufReader, BufRead};
fn main() {
let path = "/usr/share/dict/words";
let f = File::open(path).expect("Can't open file");
let buffered = BufReader::new(f);
for line_result in buffered.lines() {
let line = line_result.unwrap();
if line.contains("rust") {
println!("{}", line);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment