3 releases
0.1.2 | Oct 20, 2021 |
---|---|
0.1.1 | Oct 20, 2021 |
0.1.0 | Oct 20, 2021 |
#7 in #fatal
4KB
Fateful
A tool to fatefully exit the process without panics
Install
Add to your cargo.toml
file
[dependencies]
fateful = "0.1.1"
Usage
use std::env;
use rand;
use fateful::{fatal, err_prefix};
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 3 {
fatal!(err_prefix!(), "missing random items to choose of");
}
let random_items: &Vec<String> = &args[1..args.len()].to_vec();
let index = (rand::random::<f32>() * random_items.len() as f32).floor() as usize;
println!("U need to study: {} 🎉", random_items[index]);
}
If u don't provide at least 2 arguments after cargo run
the output will be:
Error: missing random items to choose of
lib.rs
:
A tool to fatefully exit the process without panics
(Pseudo-)Example:
use std::env;
use rand;
use fateful::fatal;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 3 {
fatal!("missing random items to choose of");
}
let random_items: &Vec<String> = &args[1..args.len()].to_vec();
let index = (rand::random::<f32>() * random_items.len() as f32).floor() as usize;
println!("Random: {} 🎉", random_items[index]);
}