some practical Rust utilities because i got tired of writing the same crap over and over
basically, this is my little Rust utility crate for things i find useful enough to not want to rewrite every time
it currently has utilities for console input/output, collections, and math, with more stuff probably getting added as i go
console-- convenient console input and outputcollections-- useful helpers for vectors and slicesmath-- common mathematical utilities
- Rust
- Cargo
cargo add jstdlibor add it manually to your Cargo.toml:
[dependencies]
jstdlib = "0.1.1"use jstdlib::console::Console;
Console::write_line("Hello, world!");
let name: String = Console::input("What's your name? ");
let age: i32 = Console::input("How old are you? ");
Console::write_line(&format!("Hello, {name}!"));
Console::write_line(&format!("You are {age} years old."));you can also use the formatting macros if you wanna keep things concise or don't wanna use the ugly &format!() boilerplate:
use jstdlib::write_line;
let name = "Someone";
let age = 21;
write_line!("Name: {name}");
write_line!("Age: {age}");use jstdlib::collections::vec;
let numbers = vec![1, 2, 3, 4, 5, 6];
let even = vec::filter(&numbers, |x| x % 2 == 0);
let doubled = vec::map(&numbers, |x| x * 2);
let found = vec::find(&numbers, |x| *x > 4);
println!("{even:?}");
println!("{doubled:?}");
println!("{found:?}");currently available:
filtermapfindanyallcountuniquechunkpartition
i might've genuinely missed some, just check (if you want)
use jstdlib::math::{gcd, lcm, lerp};
let greatest = gcd(48, 18);
let least = lcm(12, 18);
let interpolated = lerp(0.0, 100.0, 0.25);
println!("GCD: {greatest}");
println!("LCM: {least}");
println!("Lerp: {interpolated}");See LICENSE.