Skip to content

Instantly share code, notes, and snippets.

Last active October 22, 2019 00:00
What would you like to do?
Fourth Checkpoint, Getting Started with Rust by Building a Tiny Markdown Compiler (
// Code for the Fourth Checkpoint
// Tutorial:
// The purpose of this checkpoint is to ensure that you have a complete copy
// of the code in the tutorial up to the checkpoint. I want you to tinker and
// explore, but to keep up with the rest of the tutorial, make sure your
// code matches this checkpoint.
fn parse_markdown_file(_file: &str) {
println!("[ INFO ] Trying to parse {}...", _file);
fn get_title() -> String {
let mut the_title = String::from(env!("CARGO_PKG_NAME"));
the_title.push_str(" (v");
the_title.push_str("), ");
return the_title;
fn print_short_banner() {
println!("{}", get_title());
fn print_long_banner() {
println!("Written by: {}\nHomepage: {}\nUsage: tinymd <somefile>.md\n",
fn usage() {
fn main() {
// Collect all arguments in a vector
let args: Vec<String> = std::env::args().collect();
// Match the number of arguments. We only want ONE, which means we
// should have a vector length of 2: one for the name of the program,
// and another for the mardown file we want to parse.
match args.len() {
1 => {
println!("[ ERROR ] You forgot to specify the markdown file to parse!");
// The correct number of args
2 => {
_ => {
println!("[ ERROR ] Confusing invocation. See usage below.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment