Crates.io | discretionary |
lib.rs | discretionary |
version | 0.1.0 |
source | src |
created_at | 2021-12-26 20:16:25.78847 |
updated_at | 2021-12-26 20:16:25.78847 |
description | A tiny procedural macro to make all your struct fields optional |
homepage | https://github.com/dfm/discretionary |
repository | https://github.com/dfm/discretionary.git |
max_upload_size | |
id | 503439 |
size | 16,701 |
A tiny procedural macro to make all your struct fields optional. For now, this
package is essentially trivial, although it might be useful if you have some
huge struct
that needs to have all its field types converted from T
to
Option<T>
. (I needed that and now this exists!)
Add discretionary
as a dependency in your Cargo.toml
:
[dependencies]
discretionary = "0.1"
Then decorate your struct
with the #[make_optional]
macro. That's it!
For example, the following
use discretionary::make_optional;
#[make_optional]
struct ExampleStruct {
id: usize,
name: String,
}
will be re-written to something like
struct ExampleStruct {
id: Option<usize>,
name: Option<String>,
}