mirror of
https://github.com/Noratrieb/simple-std.git
synced 2026-01-14 16:35:06 +01:00
added Ordering use and added example to lib.rs
This commit is contained in:
parent
9a18b81523
commit
1991397ecf
2 changed files with 18 additions and 18 deletions
|
|
@ -33,6 +33,7 @@ fn main() {
|
|||
Guessing game
|
||||
|
||||
```rust
|
||||
use std::cmp::Ordering;
|
||||
use simple_std::{prompt, random_int_range};
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
35
src/lib.rs
35
src/lib.rs
|
|
@ -1,24 +1,23 @@
|
|||
//!
|
||||
//! # Example: guessing game
|
||||
//! ```
|
||||
//! use simple_std::{prompt, random_int_range};
|
||||
//!
|
||||
//! let number = random_int_range(0..100);
|
||||
//! loop {
|
||||
//!# // hack the input function for this to work in the doc test
|
||||
//!# fn prompt(_str: &str) -> String {
|
||||
//!# random_int_range(0..100).to_string()
|
||||
//!# }
|
||||
//! let input = prompt("guess: ").parse::<i32>().expect("not a number");
|
||||
//! if input < number {
|
||||
//! println!("Higher");
|
||||
//! } else if input > number {
|
||||
//! println!("Lower");
|
||||
//! } else {
|
||||
//! println!("Correct!");
|
||||
//! break;
|
||||
//! }
|
||||
//! }
|
||||
//! use std::cmp::Ordering;
|
||||
// use simple_std::{prompt, random_int_range};
|
||||
//
|
||||
// fn main() {
|
||||
// let number = random_int_range(0..100);
|
||||
// loop {
|
||||
// let input = prompt("Guess: ").parse::<i32>().expect("not a number");
|
||||
// match input.cmp(&number) {
|
||||
// Ordering::Less => println!("Too Small"),
|
||||
// Ordering::Greater => println("Too Big"),
|
||||
// Ordering::Equal => {
|
||||
// println("You win!");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//! ```
|
||||
|
||||
pub use io::{input, prompt};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue