From 21f8b532413a5dad99636780cf620ec0d5a52ddc Mon Sep 17 00:00:00 2001 From: kud1ing Date: Sat, 10 Dec 2016 19:23:48 +0100 Subject: [PATCH] cleanup --- src/main.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 326b812..9a2fa35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,24 +7,27 @@ use std::io::Read; use std::path::Path; fn main() { - let path = Path::new("README.md"); + let readme_file_path = Path::new("README.md"); - let display = path.display(); + let display = readme_file_path.display(); - let mut file = match File::open(&path) { - Err(why) => panic!("couldn't open {}: {}", display, why.description()), + // Try to open the README.md file. + let mut file = match File::open(&readme_file_path) { + Err(why) => panic!("could not open \"{}\": {}", display, why.description()), Ok(file) => file, }; - let mut readme_content = String::new(); + let mut readme_file_content = String::new(); - match file.read_to_string(&mut readme_content) { - Err(why) => panic!("couldn't read {}: {}", display, why.description()), - Ok(_) => print!("{} contains:\n{}", display, readme_content), + // Try to read the README.md file in a string. + if let Err(why) = file.read_to_string(&mut readme_file_content) { + panic!("couldn't read {}: {}", display, why.description()); } - let mut parser = Parser::new(&readme_content); + // Parse the Markdown string. + let mut parser = Parser::new(&readme_file_content); + // Iterate over the Markdown entities. while let Some(event) = parser.next() { match event { Event::Start(tag) => println!("start: {:?}", tag),