diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e420ee4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/* diff --git a/rust-book/chapter-1/guessing_game/.gitignore b/rust-book/chapter-1/guessing_game/.gitignore index 53eaa21..088ba6b 100644 --- a/rust-book/chapter-1/guessing_game/.gitignore +++ b/rust-book/chapter-1/guessing_game/.gitignore @@ -1,2 +1,10 @@ -/target +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt **/*.rs.bk diff --git a/rust-book/chapter-1/guessing_game/Cargo.toml b/rust-book/chapter-1/guessing_game/Cargo.toml index 237179e..db0cb69 100644 --- a/rust-book/chapter-1/guessing_game/Cargo.toml +++ b/rust-book/chapter-1/guessing_game/Cargo.toml @@ -7,4 +7,5 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rand = "0.3.14" +rand = "0.4.0" +ferris-says = "0.1" diff --git a/rust-book/chapter-1/guessing_game/src/main.rs b/rust-book/chapter-1/guessing_game/src/main.rs index 4fc83aa..bccadda 100644 --- a/rust-book/chapter-1/guessing_game/src/main.rs +++ b/rust-book/chapter-1/guessing_game/src/main.rs @@ -1,19 +1,27 @@ +use ferris_says::say; +use rand::Rng; use std::io; fn main() { println!("Guess the number!"); + let secret_number = rand::thread_rng().gen_range(1, 101); + + let stdout = io::stdout(); + let output = b"I will generate a number!"; + let width = 28; + + let mut writer = io::BufWriter::new(stdout.lock()); + say(output, width, &mut writer).unwrap(); + + println!("The secret number is {}", secret_number); + println!("Please input your guess."); let mut guess = String::new(); - io::stdin() .read_line(&mut guess) .expect("Failed to read line"); println!("You guessed: {}", guess); } - -fn test(arg: String) -> String { - unimplemented!() -}