Table of content

What is this :grey_question:

The rules of the game are explained in my original post.

46th Challenge

Challenge

Going back to my original source of information I’m going to challenge my self with chapter 12 of ‘the book’. Insteand of doing the same example I will make the a cat instead of a grep clone.

Solution :white_check_mark:

Here is the comparision of cat and cli-tutorial.

	$ ./cli-tutorial hello-world.txt 
	This is a test.
	This worked just like cat.
	$ cat hello-world.txt 
	This is a test.
	This worked just like cat.
	$ 
	

And here is the very simple code for it:

	use std::env;
	use std::fs;

	fn main() {
	    let args: Vec<String> = env::args().collect();

	    if args.len() != 2 {
	        panic!("This program takes exactly one argument, the file name.")
	    }

	    let filname = &args[1];
	    let contents = fs::read_to_string(filname)
	        .expect("Something went wrong reading the file");

	    print!("{}", contents);
	}
	

See github for today’s simple snippet.