st-map

Crates.iost-map
lib.rsst-map
version0.2.4
sourcesrc
created_at2019-12-15 11:36:01.682364
updated_at2024-08-08 08:07:33.119911
descriptionRuntime for a stack-alocated map
homepage
repositoryhttps://github.com/dudykr/ddbase.git
max_upload_size
id189531
size15,957
Donny/강동윤 (kdy1)

documentation

README

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

Commit count: 45

cargo fmt