Function serde_aux::field_attributes::bool_true
source · pub fn bool_true() -> boolExpand description
Allows a bool field to be defaulted to true, rather than the normal
default of false. Useful for fields where the default value should be true`.
Example:
use serde_aux::prelude::*;
#[derive(serde::Deserialize, Debug)]
struct MyStruct {
#[serde(default)]
default_false: bool,
#[serde(default = "bool_true")]
default_true: bool,
}
let s = r#" { } "#;
let a: MyStruct = serde_json::from_str(s).unwrap();
assert!(!a.default_false);
assert!(a.default_true);