Expand description
This crate provides a derive macro that makes it easy to create nullable versions of structs.
The Nullable
derive macro wraps each field of a struct in an Option<T>
type, allowing any field to be set to None
.
It also generates helper methods for getting, setting, and initializing these optional fields.
§Example
use your_crate_name::Nullable;
#[derive(Nullable)]
struct MyStruct {
field1: i32,
field2: String,
}
let s = NullableTestStruct::new(42, "hello".to_string());
assert_eq!(s.field1(), 42);
assert_eq!(s.field2(), "hello".to_string());
assert_eq!(instance.field1(), 42);
assert_eq!(instance.field2(), "Hello, World!".to_string());
Derive Macros§
- Nullable
- Derive macro to make a struct “nullable” by wrapping all of its fields in
Option<T>
and generating convenient getter and setter methods for these fields.