optfield

crates.io Released API docs Minimum rustc version CI

optfield is a macro that, given a struct, generates another struct with the same fields, but wrapped in Option<T>.

Minimum rustc version: 1.33.0

Install

Add with [cargo edit]: cargo add optfield

or add to Cargo.toml: toml [dependencies] optfield = "0.2.0"

Use

optfield takes the opt struct name as its first argument: ```rust use optfield::optfield;

[optfield(Opt)]

struct MyStruct { text: String, number: i32, generic: T, } This will generate another struct that looks like: rust struct Opt { text: Option, number: Option, generic: Option, } ```

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.