12 releases

0.2.4 Aug 8, 2024
0.2.3 Jan 5, 2024
0.2.2 Dec 18, 2023
0.2.0 Jun 21, 2023
0.1.4 Dec 24, 2019

#135 in Rust patterns

Download history 23609/week @ 2024-07-18 12546/week @ 2024-07-25 22345/week @ 2024-08-01 21519/week @ 2024-08-08 34555/week @ 2024-08-15 23919/week @ 2024-08-22 14121/week @ 2024-08-29 13772/week @ 2024-09-05 7439/week @ 2024-09-12 11546/week @ 2024-09-19 9483/week @ 2024-09-26 11809/week @ 2024-10-03 14422/week @ 2024-10-10 11776/week @ 2024-10-17 14151/week @ 2024-10-24 13829/week @ 2024-10-31

54,740 downloads per month
Used in 76 crates (2 directly)

Apache-2.0

8KB

st-map

Stack-allocated map.

Usage

use st_map::StaticMap;

#[derive(Debug, PartialEq, Default, StaticMap)]
struct BrowserData<T: Default> {
    chrome: T,
    safari: T,
    android: T,
}

#[test]
fn usage_iter() {
    let mut data = BrowserData {
        chrome: true,
        safari: false,
        android: true,
    };
    assert_eq!(
        data.iter().collect::<Vec<_>>(),
        vec![("chrome", &true), ("safari", &false), ("android", &true),]
    );

    assert_eq!(
        data.iter_mut().collect::<Vec<_>>(),
        vec![
            ("chrome", &mut true),
            ("safari", &mut false),
            ("android", &mut true),
        ]
    );

    assert_eq!(
        data.into_iter().collect::<Vec<_>>(),
        vec![("chrome", true), ("safari", false), ("android", true),]
    );
}

#[test]
fn usage_map() {
    let data = BrowserData {
        chrome: 20000,
        safari: 10000,
        ..Default::default()
    };

    assert_eq!(
        data.map_value(|v| v > 15000),
        BrowserData {
            chrome: true,
            safari: false,
            android: false,
        }
    );
}

License

Apache-2.0

Dependencies

~290–740KB
~17K SLoC