Crate utilz_rs

Source
Expand description

§Utilz

Ergonomic utility traits for Rust with zero dependencies by default.

utilz provides a curated set of extension traits for common Rust types like Option, Result, Vec, bool, &str, HashMap, and more — to help you write cleaner, shorter, and more expressive code.


§Highlights

  • Log – Simple in-memory logger with optional async support – .log_info(), .log_warn(), .print_logs(), .set_up_logger(), .clear()

  • OptionUtils – More ergonomic handling of Option<T>.if_some(), .or_default_with()

  • ResultUtils – Sugar methods for Result<T, E>.if_ok(), .if_err(), .unwrap_or_exit()

  • BoolUtils – Conditionals made fancy – .toggle(), .not(), .then_val(), .if_true(), .if_false()

  • VecUtils – Push conditionally into vectors – .push_if(), .push_if_with()

  • StrUtils – Extensions for &str.contains_all(), .contains_any(), .to_title_case()

  • MapUtilsHashMap helpers – .insert_if(), .get_or()

  • MemUtils – Reflection-like methods – .type_name(), .mem_size(), .view()

  • IdentityUtils – Tap-style chaining – .tap()

  • PanicUtils – Fatal exit helpers – .unwrap_or_exit()

  • DurationUtils – Duration formatting – .pretty()"1h 2m 3s"

  • ConvertUtils – Easy type conversions with TryFrom.to(), .to_or(), .to_result()

  • ClampUtils – Range limiting for numbers – .clamp_to(min, max)

  • NumberUtils – Integer extensions – .is_even(), .is_odd()

  • IteratorUtils – Fallback logic for iterators – .find_map_or(f, fallback)


§✨ Quick Example

use utilz_rs::*;

let value = Some("hi");
value.if_some(|v| println!("Got: {v}"));

let mut enabled = true;
enabled.toggle();

let name = "hello world";
assert!(name.contains_all(["hello", "world"]));

let duration = std::time::Duration::from_secs(3666);
println!("{}", duration.pretty()); // → "1h 1m 6s"

§Philosophy

  • ✅ 100% Rust standard library
  • 🔧 Zero dependencies by default
  • 🔌 Async logging via optional feature flag
  • 🙌 Opt-in trait imports: use only what you need

Use what you want, ignore the rest. No macros. No surprises.

Modules§

bool_utils
logger
option_utils
prelude
str_utils

Traits§

ClampUtils
ConvertUtils
DurationUtils
Pretty-formatting for Duration.
EqUtils
Provides sugar methods for comparing values.
IdentityUtils
IteratorUtils
MapUtils
MemUtils
Reflection helpers: type name and memory size.
NumberUtils
PanicUtils
Helpers to panic or exit cleanly with messages.
ResultUtils
VecUtils
Conditional vector push helpers.