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


browse  log 



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


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.