Skip to main content

IsDefault

Trait IsDefault 

Source
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(), "{}");

Required Methods§

Source

fn is_default(&self) -> bool

Implementors§

Source§

impl<T> IsDefault for T
where T: Default + PartialEq,