option-filter 1.0.2

Option::filter polyfill for Rust 1.26 and older
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented1 out of 3 items with examples
  • Size
  • Source code size: 3.83 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.12 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • lambda-fairy/option-filter
    7 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • lambda-fairy

option-filter Cargo

This crate adds a .filter() method to Option<T>, for older versions of Rust that don't provide it.

Note: Option::filter was added to the standard library in Rust 1.27. Unless you need to support older versions of Rust, you do not need to use this crate.

Usage

To use it, add option-filter to your Cargo.toml:

[dependencies]
option-filter = "1.0"

Then import the extension trait:

extern crate option_filter;
use option_filter::OptionFilterExt;

Now you can filter your Options!

let answer = Some(42);
assert_eq!(answer.filter(|x| *x == 42), Some(42));
assert_eq!(answer.filter(|x| *x == 43), None);