Crates.io | optfield |
lib.rs | optfield |
version | |
source | src |
created_at | 2020-04-10 17:08:00.884469 |
updated_at | 2024-12-06 16:44:44.292574 |
description | A macro that generates structs with optional fields |
homepage | |
repository | https://github.com/roignpar/optfield |
max_upload_size | |
id | 228407 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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.