Created
January 3, 2020 06:53
-
-
Save seasonedgeek/581b4b331966e0a6b429f6a18e953779 to your computer and use it in GitHub Desktop.
My experiment with "Programming A Guessing Game" @https://doc.rust-lang.org/book/ch02-00-guessing-game-tutorial.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A game | |
pub mod guess_number { | |
/// Announces the game to be played | |
pub fn announce_game() { | |
println!(""); | |
println!("--------------------------"); | |
println!("| Guess A Number! |"); | |
println!("--------------------------"); | |
} | |
/// Pick a number, any number | |
pub fn pick_number() -> String { | |
use std::io; | |
println!(" Make a guess: "); | |
let mut guess = String::new(); | |
io::stdin().read_line(&mut guess).expect("ERROR - Failed to read line."); | |
return guess; | |
} | |
/// Publishes the number | |
pub fn tell_world(numb: String) { | |
println!(" You guessed: {}", numb); | |
} | |
} | |
/// A game played | |
fn main() { | |
guess_number::announce_game(); | |
let who_knew = guess_number::pick_number(); | |
guess_number::tell_world(who_knew); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am exploring the capabilities of Rust in comparison to some other languages I know. I spent a couple hours this evening in the Rust Docs, and Rust by Example while working on and debugging my extended Programming A Guessing Game solution via
cargo {check, build, run}
on the command line. It was very interesting.