| Crates.io | optfield |
| lib.rs | optfield |
| version | 0.4.0 |
| created_at | 2020-04-10 17:08:00.884469+00 |
| updated_at | 2024-12-06 16:44:44.292574+00 |
| description | A macro that generates structs with optional fields |
| homepage | |
| repository | https://github.com/roignpar/optfield |
| max_upload_size | |
| id | 228407 |
| size | 81,938 |
optfield is a macro that, given a struct, generates another struct with
the same fields, but wrapped in Option<T>.
Minimum rustc version: 1.61.0
cargo add optfield
optfield takes the opt struct name as its first argument:
use optfield::optfield;
#[optfield(Opt)]
struct MyStruct<T> {
text: String,
number: i32,
generic: T,
}
This will generate another struct that looks like:
struct Opt<T> {
text: Option<String>,
number: Option<i32>,
generic: Option<T>,
}
optfield supports defining visibility, documentation, attributes and merge
methods. For more details and examples check its documentation.
Licensed under either of Apache License, Version 2.0 or MIT at your option.