is_default/
lib.rs

1#![doc = include_str!("../README.md")]
2#![cfg_attr(not(feature = "std"), no_std)]
3#![cfg_attr(feature = "ascii_char", feature(ascii_char, ascii_char_variants))]
4#![cfg_attr(feature = "bstr", feature(bstr))]
5#![cfg_attr(feature = "f16", feature(f16))]
6#![cfg_attr(feature = "f128", feature(f128))]
7
8#[cfg(feature = "derive")]
9extern crate is_default_derive;
10#[cfg(feature = "derive")]
11pub use is_default_derive::IsDefault;
12
13/// Checks whether a value is equal to its type's default.
14pub trait IsDefault {
15    /// Returns `true` if `self` is equal to the default value for its type.
16    ///
17    /// Implementations must ensure that the condition `self == &Self::default()` holds.
18    fn is_default(&self) -> bool;
19}
20
21#[cfg(not(feature = "via_default_eq"))]
22mod not_via_default_eq;
23
24#[cfg(feature = "via_default_eq")]
25mod via_default_eq {
26    use crate::IsDefault;
27
28    impl<T> IsDefault for T
29    where
30        T: Default + PartialEq,
31    {
32        fn is_default(&self) -> bool {
33            self == &Self::default()
34        }
35    }
36}