https://github.com/lambda-fairy/option-filter
Adds a .filter() method to Option<T>
https://github.com/lambda-fairy/option-filter
Last synced: 8 months ago
JSON representation
Adds a .filter() method to Option<T>
- Host: GitHub
- URL: https://github.com/lambda-fairy/option-filter
- Owner: lambda-fairy
- Created: 2016-10-04T09:30:06.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-06-22T07:39:43.000Z (about 8 years ago)
- Last Synced: 2025-04-09T10:48:41.542Z (over 1 year ago)
- Language: Rust
- Homepage: https://docs.rs/option-filter
- Size: 2.93 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# option-filter [](https://crates.io/crates/option-filter)
This crate adds a `.filter()` method to `Option`, for older versions of Rust that don't provide it.
**Note: [`Option::filter`][std] was added to the standard library in [Rust 1.27][rust]. Unless you need to support older versions of Rust, you do not need to use this crate.**
[std]: https://doc.rust-lang.org/std/option/enum.Option.html#method.filter
[rust]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1270-2018-06-21
## Usage
To use it, add `option-filter` to your `Cargo.toml`:
```toml
[dependencies]
option-filter = "1.0"
```
Then import the extension trait:
```rust,ignore
extern crate option_filter;
use option_filter::OptionFilterExt;
```
Now you can filter your `Option`s!
```rust
let answer = Some(42);
assert_eq!(answer.filter(|x| *x == 42), Some(42));
assert_eq!(answer.filter(|x| *x == 43), None);
```