| Crates.io | nullable_struct |
| lib.rs | nullable_struct |
| version | 0.1.0 |
| created_at | 2023-09-04 03:56:58.651888+00 |
| updated_at | 2023-09-04 03:56:58.651888+00 |
| description | A derive macro that makes it easy to create nullable versions of structs. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 962615 |
| size | 24,212 |
nullable_structs is a Rust crate that provides a Nullable derive macro. This macro makes it incredibly easy to create structs where each field is wrapped in Option
[dependencies]
nullable_struct = "0.1.0"
Here is a basic example demonstrating how to use nullable_struct.
extern crate nullable_structs;
use nullable_struct::Nullable;
#[derive(Nullable)]
struct MyStruct {
field1: i32,
field2: String,
}
fn main() {
let mut instance = NullableMyStruct::new(42, "Hello".to_string());
println!("Field1: {}", instance.field1()); // Output: 42
println!("Field2: {}", instance.field2()); // Output: Hello
instance.set_field1(13);
instance.set_field2("World".to_string());
if let Some(value) = instance.get_field1() {
println!("Field1 exists: {}", value); // Output: 13
}
if let Some(value) = instance.get_field2() {
println!("Field2 exists: {}", value); // Output: World
}
}
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.