try_traits/default.rs
1//! Try traits for [`core::default`].
2
3/// The try trait for [`Default`].
4pub trait TryDefault : Sized {
5 /// The type returned in the event of an error.
6 type Error;
7
8 /// The fallible equivalent of [`Default::default`].
9 fn try_default() -> Result<Self, Self::Error>;
10}
11
12
13impl<T: Default> TryDefault for T {
14 type Error = crate::Infallible;
15
16 #[inline]
17 fn try_default() -> Result<Self, Self::Error> {
18 Ok(Self::default())
19 }
20}