maybe-trait 1.0.0

Allows writing functions which are polymorphic over taking an option.
Documentation
  • Coverage
  • 33.33%
    1 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 1.95 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 69.11 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Quelfth

This crate provides the Maybe trait which is implemented for both T and Option<T>. The purpose is so that you can write functions like this:

fn foo(param: impl Maybe<Foo>) {
    if let Some(value) = param.maybe() {
        do_something_with(value)
    } else {
        do_something_else()
    }
}

This way you never need to write foo(Some(x)).