Crate option_filter[−][src]
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.
To use it, add option-filter
to your Cargo.toml
:
[dependencies]
option-filter = "1.0"
Then import the extension trait:
ⓘThis example is not tested
extern crate option_filter; use option_filter::OptionFilterExt;
Now you can filter your Option
s!
let answer = Some(42); assert_eq!(answer.filter(|x| *x == 42), Some(42)); assert_eq!(answer.filter(|x| *x == 43), None);
Traits
OptionFilterExt |
Extension trait for adding a |