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

#146 in Rust patterns

Download history 10975/week @ 2024-09-28 14248/week @ 2024-10-05 13330/week @ 2024-10-12 12298/week @ 2024-10-19 13471/week @ 2024-10-26 11848/week @ 2024-11-02 10402/week @ 2024-11-09 9068/week @ 2024-11-16 8075/week @ 2024-11-23 12428/week @ 2024-11-30 10341/week @ 2024-12-07 11684/week @ 2024-12-14 10125/week @ 2024-12-21 14735/week @ 2024-12-28 21318/week @ 2025-01-04 18988/week @ 2025-01-11

66,745 downloads per month
Used in 84 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

~275–720KB
~17K SLoC