and_then_some

Crates.ioand_then_some
lib.rsand_then_some
version1.0.0
sourcesrc
created_at2020-05-15 17:10:51.957153
updated_at2020-05-15 17:10:51.957153
descriptionProvides an extension trait for `bool` with methods that return `Option`
homepage
repositoryhttps://git.sr.ht/~jplatte/and_then_some
max_upload_size
id242005
size6,089
Jonas Platte (jplatte)

documentation

README

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.

Commit count: 0

cargo fmt