Crates.io | fateful |
lib.rs | fateful |
version | 0.1.2 |
source | src |
created_at | 2021-10-20 14:21:23.861298 |
updated_at | 2021-10-20 14:38:53.590232 |
description | A tool to fatefully exit the process without panics |
homepage | |
repository | https://github.com/nilpntr/fateful.rs |
max_upload_size | |
id | 467935 |
size | 3,069 |
A tool to fatefully exit the process without panics
Add to your cargo.toml
file
[dependencies]
fateful = "0.1.1"
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