fateful

Crates.iofateful
lib.rsfateful
version0.1.2
sourcesrc
created_at2021-10-20 14:21:23.861298
updated_at2021-10-20 14:38:53.590232
descriptionA tool to fatefully exit the process without panics
homepage
repositoryhttps://github.com/nilpntr/fateful.rs
max_upload_size
id467935
size3,069
Sam Mobach (nilpntr)

documentation

README

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
Commit count: 4

cargo fmt