#utilities #stupid #collection #hash-map #zero-cost #script #optional

stupid_utils

A crate that provides some simple and maybe stupid or useful tools

15 unstable releases (3 breaking)

0.4.1 Sep 14, 2024
0.3.0 Sep 7, 2024
0.2.7 Jul 9, 2024
0.2.4 Sep 28, 2023

#373 in Rust patterns

Download history 25/week @ 2024-07-01 108/week @ 2024-07-08 3/week @ 2024-07-15 93/week @ 2024-07-29 124/week @ 2024-08-26 460/week @ 2024-09-02 269/week @ 2024-09-09 156/week @ 2024-09-16 4/week @ 2024-09-23 85/week @ 2024-09-30 19/week @ 2024-10-07

298 downloads per month
Used in computercraft_websocket_c…

MIT/Apache

63KB
1.5K SLoC

Description

A crate that provides some simple and maybe stupid or useful tools

Most of the features are zero-cost, all non-zero-cost feature can be disabled by disable_non_zerocost feature flag.

All dependencies and build script are optional, so the code can be simply copy and paste to another project to use.

Example

    use std::collections::HashMap;
    use stupid_utils::prelude::*;

    let a = HashMap::new().mutable_init(|m| {
        m.insert(1, 4.box_up());
        m.insert(
            2,
            Some(9)
                .map_value(|v| match v {
                    Some(v) => v,
                    None => 3,
                })
                .box_up(),
        );
        let cond = true;
        m.insert(cond.select(3, 4), select(cond, 3, 4).box_up());
    });

    let b = {
        let mut m = HashMap::new();
        m.insert(1, Box::new(4));
        m.insert(
            2,
            Box::new({
                let v = Some(9);
                match v {
                    Some(v) => v,
                    None => 3,
                }
            }),
        );
        let cond = true;
        m.insert(if cond { 3 } else { 4 }, Box::new(if cond { 3 } else { 4 }));
        m
    };

    assert_eq!(a, b);
   

Dependencies

~115KB