possibly 1.0.0

Like matches!(), but returning an Option type.
Documentation
  • Coverage
  • 0%
    0 out of 2 items documented0 out of 0 items with examples
  • Size
  • Source code size: 2.01 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.03 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • rnza0u/main
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Hakhenaton

possibly

A single exported macro called possibly!(), which works std::matches!() but allowing to return a value when the values matches.

It can be useful if you want to use pattern matching without dealing with extra cases.

The result is wrapped inside an Option.

Usage

use possibly::possibly;

enum MyEnum {
    Foo(u32),
    Bar
}

let value = MyEnum::Foo(1);

// basic usage with simple match arm
assert_eq!(
    possibly!(value, MyEnum::Foo(b) => b), 
    Some(1)
);

// with match arm condition
assert_eq!(
    possibly!(value, MyEnum::Foo(b) if i > 5 => b),
    None
);