pub fn is_empty<T>(t: &T) -> boolwhere
T: IsEmpty,Expand description
Thin wrapper function around IsEmpty::is_empty. Use it with serde’s skip_serializing_if attribute.
use is_empty::IsEmpty;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, IsEmpty)]
struct Foo {
client_ip: Option<String>,
client_country: Option<String>,
}
#[derive(Serialize, Deserialize)]
struct Root {
#[serde(skip_serializing_if = "is_empty::is_empty")]
foo: Foo,
}
let empty_foo = Foo { client_ip: None, client_country: None };
let root = Root { foo: empty_foo };
assert_eq!(serde_json::to_string(&root).unwrap(), "{}");