Implement bool_then_to_if assist

This commit is contained in:
Lukas Wirth 2021-08-10 13:03:12 +02:00
parent c5942c5284
commit b7d7dd6163
5 changed files with 241 additions and 3 deletions

View file

@ -33,6 +33,7 @@
//! ord: eq, option
//! derive:
//! fmt: result
//! bool_impl: option, fn
pub mod marker {
// region:sized
@ -568,6 +569,19 @@ mod macros {
}
// endregion:derive
// region:bool_impl
#[lang = "bool"]
impl bool {
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
if self {
Some(f())
} else {
None
}
}
}
// endregion:bool_impl
pub mod prelude {
pub mod v1 {
pub use crate::{