pub trait IsDefault {
// Required method
fn is_default(&self) -> bool;
}Expand description
Simple trait to check if the current value is the default.
This is particulary useful with serde:
use serde::Serialize;
use co_primitives::IsDefault;
#[derive(Debug, Serialize)]
pub struct Hello {
#[serde(default, skip_serializing_if = "IsDefault::is_default")]
pub world: bool,
}
assert_eq!(serde_json::to_string(&Hello { world: Default::default() }).unwrap(), "{}");