4 releases (breaking)
| 0.4.0 | Dec 6, 2024 |
|---|---|
| 0.3.0 | May 15, 2023 |
| 0.2.0 | May 6, 2021 |
| 0.1.0 | Apr 10, 2020 |
#1793 in Rust patterns
43,003 downloads per month
Used in 5 crates
(4 directly)
61KB
1.5K
SLoC
optfield
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
Install
cargo add optfield
Use
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.
License
Licensed under either of Apache License, Version 2.0 or MIT at your option.
Dependencies
~135–530KB
~13K SLoC