Crate utilz_rs

Source
Expand description

§Utilz

Ergonomic, zero-dependency utility traits for Rust.

This crate provides a collection of extension traits for common Rust types like Option, Result, Vec, bool, &str, HashMap, and more — to make your code cleaner, shorter, and more expressive without relying on macros or external dependencies.


§Highlights

  • Log – In-memory logger with filtering support

    • .log_info(), .log_warn(), .print_logs(), .set_up_logger(), .clear()
  • OptionUtils – Convenient extensions for Option<T>

    • .if_some(), .or_default_with()
  • ResultUtils – Cleaner result handling

    • .if_ok(), .if_err(), .unwrap_or_exit()
  • BoolUtils – Fancy conditionals for bool

    • .toggle(), .not(), .then_val(), .if_true(), .if_false()
  • VecUtils – Push conditionally into vectors

    • .push_if(), .push_if_with()
  • StrUtils – String slice helpers

    • .contains_all(), .contains_any(), .to_title_case()
  • MapUtils – Extensions for HashMap

    • .insert_if(), .get_or()
  • MemUtils – Reflection-like helpers

    • .type_name(), .mem_size(), .view()
  • IdentityUtils – Chainable tap() for debug or logging

  • PanicUtils – Exit on None or Err with a message

    • .unwrap_or_exit()
  • DurationUtils – Time formatting helpers

    • .pretty()"1h 2m 3s"
  • ConvertUtils – Ergonomic TryFrom helpers

    • .to(), .to_or(), .to_result()
  • ClampUtils – Limit a number to a range

    • .clamp_to(min, max)
  • NumberUtils – Integer property checks

    • .is_even(), .is_odd()
  • IteratorUtils – Iterator fallback logic

    • .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
  • 🚫 No dependencies
  • ✅ Only opt-in trait imports

Use what you want, ignore the rest.

Structs§

Log

Enums§

LogLevel

Traits§

BoolUtils
ClampUtils
ConvertUtils
DurationUtils
Pretty-formatting for Duration.
EqUtils
Provides sugar methods for comparing values.
IdentityUtils
IteratorUtils
Loggable
MapUtils
MemUtils
Reflection helpers: type name and memory size.
NumberUtils
OptionUtils
Extension methods for Option<T>.
PanicUtils
Helpers to panic or exit cleanly with messages.
ResultUtils
StrUtils
Extra methods for string slices (&str).
VecUtils
Conditional vector push helpers.