Crates.io | ctxmap |
lib.rs | ctxmap |
version | 0.5.0 |
source | src |
created_at | 2021-09-20 15:36:18.660082 |
updated_at | 2022-06-16 06:32:34.932339 |
description | A collection that can store references of different types and lifetimes. |
homepage | |
repository | https://github.com/frozenlib/ctxmap |
max_upload_size | |
id | 454058 |
size | 19,644 |
A collection that can store references of different types and lifetimes.
Add this to your Cargo.toml:
[dependencies]
ctxmap = "0.5.0"
ctxmap::schema!(Schema);
ctxmap::key!(Schema {
KEY_NO_DEFAULT: u32,
KEY_INT: u32 = 10,
KEY_DYN: dyn std::fmt::Display = 10,
KEY_STR: str = "abc",
KEY_STRING: str = format!("abc-{}", 10),
mut KEY_MUT: u32 = 30,
});
let mut m = ctxmap::CtxMap::new();
assert_eq!(m.get(&KEY_NO_DEFAULT), None);
assert_eq!(m.get(&KEY_INT), Some(&10));
assert_eq!(m[&KEY_INT], 10);
assert_eq!(&m[&KEY_STR], "abc");
m.with(&KEY_INT, &20, |m| {
assert_eq!(m[&KEY_INT], 20);
});
assert_eq!(m[&KEY_INT], 10);
assert_eq!(m[&KEY_MUT], 30);
m[&KEY_MUT] = 40;
assert_eq!(m[&KEY_MUT], 40);
m.with_mut(&KEY_MUT, &mut 50, |m| {
assert_eq!(m[&KEY_MUT], 50);
m[&KEY_MUT] = 60;
assert_eq!(m[&KEY_MUT], 60);
});
assert_eq!(m[&KEY_MUT], 40);
This project is dual licensed under Apache-2.0/MIT. See the two LICENSE-* files for details.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.