optional_struct

Attribute Macro optional_struct 

Source
#[optional_struct]
Expand description

The core of this crate. Call this proc macro on your structures to generate another structure containing Optional fields, as well as helpers functions to convert those optional_struct to their base, or even update only fields that have been set. This makes aggregating structures from different sources (e.g. configuration from file/env/CLI) simple. The generated struct by default will wrap all fields in an Option, unless the field already is an Option. There are however other attributes that one can use to enforce a different behaviour: optional_rename => rename the type in the generated structure. Useful when the nested structure itself has an optional_struct. This enables arbitrary nesting of optional_struct (see tests for examples). optional_skip_wrap => this force not wrapping a value, e.g. T stays T. This is enabled by default if T is a Optiona<U>. optional_wrap => this forces wrapping a value, e.g. U becomes Option<U>. Enabling this allows nested Option, e.g. Option<V> can become Option<Option<V>> optional_serde_skip_none => This generate an extra #[serde(skip_serializing_if = ... )] to the generated structures. Useful if you want to (de)serialize those structures with serde.