pub trait TryDefault<V> {
// Required method
fn try_default() -> Result<V, DefaultNotFound>;
}Expand description
A trait for all types!
If the type has a Default value,
use ::try_default::TryDefault;
// Set to `Some(0)`.
let default_num = <u32>::try_default();
// Set to `None`, as `::std::fs::File` has no `Default`.
let default_file = <::std::fs::File>::try_default();Required Methods§
Sourcefn try_default() -> Result<V, DefaultNotFound>
fn try_default() -> Result<V, DefaultNotFound>
If the implementor implements Default, then this will return
Option::Some(Default::default()).
Otherwise it returns Option::None.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.