1 stable release
1.0.1 | Oct 8, 2022 |
---|
#1578 in Data structures
Used in struct_mapping_derive
8KB
72 lines
StructMapping
StructMapping is a library for create string-based accessors/mutators Rust data structure.
Work In Progress
- Clean-Up
- Pipeline
- Publish Crate/Cargo
StructMapping in action
Click to show Cargo.toml.
[dependencies]
# The core APIs
struct_mapping = { version = "1.0", features = ["derive"] }
use struct_mapping::{StructMapping, ToStructMappingField};
fn main() {
#[derive(Default)]
struct DeepTestStruct {}
#[derive(StructMapping, Default)]
struct TestStruct {
#[struct_mapping(rename = "jimmy", alias = "jian_yang")]
jian: u32,
#[struct_mapping(skip)]
#[allow(dead_code)]
deep: DeepTestStruct,
}
let mut ex = TestStruct::default();
// print "0"
println!("{}", ex.sm_get("jimmy").unwrap());
ex.sm_set("jimmy", "128").unwrap();
// print "128"
println!("{}", ex.sm_get("jimmy").unwrap());
// print ["jimmy", "jian_yang"]
println!("{:?}", TestStruct::sm_list());
}
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in struct_mapping by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Dependencies
~0–280KB