#filter #older #options #polyfill

no-std option-filter

Option::filter polyfill for Rust 1.26 and older

3 stable releases

Uses old Rust 2015

1.0.2 Jun 22, 2018
1.0.1 Oct 4, 2016

#2420 in Rust patterns

Download history 33/week @ 2024-03-04 14/week @ 2024-03-11 13/week @ 2024-03-18 13/week @ 2024-03-25 99/week @ 2024-04-01 8/week @ 2024-04-08 14/week @ 2024-04-15 52/week @ 2024-04-22 31/week @ 2024-04-29 7/week @ 2024-05-06 16/week @ 2024-05-13 22/week @ 2024-05-20 9/week @ 2024-05-27 14/week @ 2024-06-03 23/week @ 2024-06-10 12/week @ 2024-06-17

59 downloads per month
Used in 3 crates

MIT/Apache

5KB

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);

lib.rs:

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:

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);

No runtime deps