serde_inline_default

Attribute Macro serde_inline_default 

Source
#[serde_inline_default]
Expand description

The main macro of this crate. Use it to define default values of fields in structs you Serialize or Deserialize. You do not need to create an extra function to provide the default value, as it is the case in serdes’ implementation of default (#[serde(default = "...")]).

Set this macro on a struct where you use Serialize or Deserialize and use #[serde_inline_default(...)] on the field you want to have an inline default value. Replace the ... with the value you want, and it will be set as default if serde needs it.

Note that you must set this macro before #[derive(Serialize)] / #[derive(Deserialize)] as it won’t work properly if it’s set after the derive.

§Examples

#[serde_inline_default]
#[derive(Deserialize)]
struct Test {
    #[serde_inline_default(42)]
    value: u32
}