Crates.io | set_field_macro |
lib.rs | set_field_macro |
version | 0.1.1 |
source | src |
created_at | 2023-09-09 08:22:21.246518 |
updated_at | 2023-09-09 08:29:53.263901 |
description | Derive macro for set_field |
homepage | https://github.com/0xDEADFED5/set_field |
repository | https://github.com/0xDEADFED5/set_field |
max_upload_size | |
id | 967995 |
size | 4,756 |
see set_field
use set_field::SetField;
#[derive(SetField)]
struct Foo {
a: i32,
b: Option<bool>,
c: i32,
}
fn test() {
let mut t = Foo { a: 777, b: None, c: 0 };
// return true on success:
assert_eq!(t.set_field("a", 888), true);
// return true on success:
assert_eq!(t.set_field("b", Some(true)), true);
assert_eq!(t.a, 888);
assert_eq!(t.b, Some(true));
// return false on nonexistent field:
assert_eq!(t.set_field("d", 0), false);
// return false on wrong type:
assert_eq!(t.set_field("b", 0), false);
// won't compile:
// assert_eq!(t.set_field("a", 0.0), false);
}