Crates.io | simple-std |
lib.rs | simple-std |
version | 0.1.1 |
source | src |
created_at | 2021-10-19 19:53:25.087985 |
updated_at | 2021-10-19 20:08:23.86583 |
description | A simple extension to the Rust standard library for exercises |
homepage | https://github.com/Nilstrieb/simple-std/ |
repository | https://github.com/Nilstrieb/simple-std/ |
max_upload_size | |
id | 467489 |
size | 9,965 |
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
.
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");
if input < number {
println!("Higher");
} else if input > number {
println!("Lower");
} else {
println!("Correct!");
break;
}
}
}