added Ordering use and added example to lib.rs

This commit is contained in:
angelsflyinhell 2021-10-19 22:30:41 +02:00
parent 9a18b81523
commit 1991397ecf
2 changed files with 18 additions and 18 deletions

View file

@ -33,6 +33,7 @@ fn main() {
Guessing game Guessing game
```rust ```rust
use std::cmp::Ordering;
use simple_std::{prompt, random_int_range}; use simple_std::{prompt, random_int_range};
fn main() { fn main() {

View file

@ -1,24 +1,23 @@
//! //!
//! # Example: guessing game //! # Example: guessing game
//! ``` //! ```
//! use simple_std::{prompt, random_int_range}; //! use std::cmp::Ordering;
//! // use simple_std::{prompt, random_int_range};
//! let number = random_int_range(0..100); //
//! loop { // fn main() {
//!# // hack the input function for this to work in the doc test // let number = random_int_range(0..100);
//!# fn prompt(_str: &str) -> String { // loop {
//!# random_int_range(0..100).to_string() // let input = prompt("Guess: ").parse::<i32>().expect("not a number");
//!# } // match input.cmp(&number) {
//! let input = prompt("guess: ").parse::<i32>().expect("not a number"); // Ordering::Less => println!("Too Small"),
//! if input < number { // Ordering::Greater => println("Too Big"),
//! println!("Higher"); // Ordering::Equal => {
//! } else if input > number { // println("You win!");
//! println!("Lower"); // break;
//! } else { // }
//! println!("Correct!"); // }
//! break; // }
//! } // }
//! }
//! ``` //! ```
pub use io::{input, prompt}; pub use io::{input, prompt};