Skip to content

BartMassey/prompted

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maintenance CI crates-io api-docs dependency-status

prompted: simple prompting and input

Copyright © Bart Massey 2017 (Version 0.3.0-pre)

This crate provides macros for easy non-newline-terminated flushed printing, and for input line reading. These macros are intended for new Rust users and for folks who need no more for simple applications.

Example

Here's an example adapted from the "Guessing Game" example in The Rust Programming Language.

use std::cmp::Ordering;
use prompted::inputln;

fn main() {
    println!("Guess the number!");

    let n = 100;
    let secret_number = 37;

    loop {
        let guess = inputln!("Please input your guess (1-{}): ", n);

        let guess: u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        };

        println!("You guessed: {}", guess);

        match guess.cmp(&secret_number) {
            Ordering::Less => println!("Too small!"),
            Ordering::Greater => println!("Too big!"),
            Ordering::Equal => {
                println!("You win!");
                break;
            }
        }
    }
}

License

This work is licensed under the "MIT License". Please see the file LICENSE in the source distribution of this software for license terms.

Acknowledgments

Thanks to the cargo-readme crate for generation of this README.

About

prompted input/output macros for Rust

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages