~jplatte/and_then_some

[Rust] Provides an extension trait for `bool` with methods that return `Option<T>`
e040d989 — Jonas Platte 4 years ago
Escape underscores in README.md title
d1e0e643 — Jonas Platte 4 years ago
Initial commit

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~jplatte/and_then_some
read/write
git@git.sr.ht:~jplatte/and_then_some

You can also use your local clone with git send-email.

#and_then_some

Provides an extension trait for bool with methods that return Option<T>.

This crate provides four methods; they all are defined in BoolExt, all take self and another argument, and all return Option<T>. The only difference is in the type of the second argument:

  • and: Option<T>
  • and_some: T
  • and_then: impl FnOnce() -> Option<T>
  • and_then_some: impl FnOnce() -> T

I do not consider this crate to be useful myself, I just created it to draw some attention to the tracking issue for RFC 2757 (methods for converting from bool to Option<T>).

This crate achieves maximum consistency: Some-wrapping is given a _some suffix in the method names while methods that take a function over a plain value have a _then suffix; and_then is consistent with Option::and_then in the type of its second argument. This naming scheme results in the amusing name and_then_some for one of the methods, which made me choose it as the crate name too. I hope .and_then_some can be stabilized under a different name though, because to me it seems like the most common out of the four operations.