| Crates.io | try_default |
| lib.rs | try_default |
| version | 2.0.0 |
| created_at | 2021-03-08 18:13:04.683135+00 |
| updated_at | 2024-08-19 11:04:14.328702+00 |
| description | A trait to optionally get the Default if present, or None if there is no Default. |
| homepage | |
| repository | https://github.com/JosephLenton/TryDefault |
| max_upload_size | |
| id | 365794 |
| size | 5,782 |
A 'try' version of Default, where it returns an Option::Some wrapping the default value when present.
It returns Option::None when there is no Default available.
You can in theory call this on any type to retrive it's Default, if there is one!
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();
specialization feature.