TryDefault

Trait TryDefault 

Source
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§

Source

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.

Implementors§

Source§

impl<V> TryDefault<V> for V

Source§

impl<V: Default> TryDefault<V> for V