Skip to content

Add listings #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions listings/ch02-guessing-game-tutorial/listing-02-01/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions listings/ch02-guessing-game-tutorial/listing-02-01/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "guessing_game"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
31 changes: 31 additions & 0 deletions listings/ch02-guessing-game-tutorial/listing-02-01/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ANCHOR: all
// ANCHOR: io
use std::io;
// ANCHOR_END: io

// ANCHOR: main
fn main() {
// ANCHOR_END: main
// ANCHOR: print
println!("Guess the number!");

println!("Please input your guess.");
// ANCHOR_END: print

// ANCHOR: string
let mut guess = String::new();
// ANCHOR_END: string

// ANCHOR: read
io::stdin()
.read_line(&mut guess)
// ANCHOR_END: read
// ANCHOR: expect
.expect("Failed to read line");
// ANCHOR_END: expect

// ANCHOR: print_guess
println!("You guessed: {}", guess);
// ANCHOR_END: print_guess
}
// ANCHOR: all
87 changes: 87 additions & 0 deletions listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "guessing_game"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.5.5"
15 changes: 15 additions & 0 deletions listings/ch02-guessing-game-tutorial/listing-02-02/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::io;

fn main() {
println!("Guess the 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);
}
87 changes: 87 additions & 0 deletions listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "guessing_game"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.5.5"
28 changes: 28 additions & 0 deletions listings/ch02-guessing-game-tutorial/listing-02-03/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ANCHOR: all
use std::io;
// ANCHOR: ch07-04
use rand::Rng;

fn main() {
// ANCHOR_END: ch07-04
println!("Guess the number!");

// ANCHOR: ch07-04
let secret_number = rand::thread_rng().gen_range(1, 101);
// ANCHOR_END: ch07-04

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);
// ANCHOR: ch07-04
}
// ANCHOR_END: ch07-04
// ANCHOR_END: all
87 changes: 87 additions & 0 deletions listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "guessing_game"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.5.5"
Loading