try_default 2.0.0

A trait to optionally get the Default if present, or None if there is no Default.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use std::error::Error;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;

/// Error returned if there is no default value.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct DefaultNotFound;

impl Error for DefaultNotFound {}

impl Display for DefaultNotFound {
    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
        write!(f, "The type does not implement default")
    }
}