Skip to content

Macro that generates structs with optional fields from existing structs

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

roignpar/optfield

Repository files navigation

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.56.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.

About

Macro that generates structs with optional fields from existing structs

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages