try_default 2.0.0

A trait to optionally get the Default if present, or None if there is no Default.
Documentation
  • Coverage
  • 75%
    3 out of 4 items documented1 out of 1 items with examples
  • Size
  • Source code size: 5.45 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.55 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • JosephLenton/TryDefault
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • JosephLenton

TryDefault

Current Crates.io Version

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();

Notes

  • Requires nightly for specialization feature.
  • Is possibly the world's most pointless crate. But it's here if you need it!