try_default

Crates.iotry_default
lib.rstry_default
version1.0.1
sourcesrc
created_at2021-03-08 18:13:04.683135
updated_at2023-10-14 16:19:51.198448
descriptionA trait to optionally get the Default if present, or None if there is no Default.
homepage
repositoryhttps://github.com/JosephLenton/TryDefault
max_upload_size
id365794
size5,455
Joseph Lenton (JosephLenton)

documentation

https://docs.rs/axum-test/latest/TryDefault

README

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!
Commit count: 3

cargo fmt