No description
Find a file
2021-10-19 22:18:59 +02:00
.github/workflows Create rust.yml 2021-10-19 21:57:05 +02:00
src add prompt 2021-10-19 22:08:04 +02:00
.gitignore input and random 2021-10-19 21:48:11 +02:00
Cargo.toml add prompt 2021-10-19 22:08:04 +02:00
LICENSE Create LICENSE 2021-10-19 21:49:23 +02:00
README.md use Ordering instead of if else 2021-10-19 22:18:59 +02:00

note: this is for practicing rust only, do not use this in actual production programs!

really, don't.

[dependencies]
simple-std = "0.1.1"

simple-std is a little extension to the standard library, providing additional helpers for getting input or creating random numbers.

std is very useful, but it's lacking for little beginner exercises (for a good reason), so I made this library to help with that.

Every function from this library has a little section on why this function isn't in std, to help you understand the reasoning behind including something in std.

Examples

Greeting

use simple_std::input;

fn main() {
    println!("What is your name?");
    let name = input();
    println!("Hello {}!", name)
}

Guessing game

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;
            }
        }
    }
}