Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Introduce `when_else()`

Joseph T. Lyons8fc15c05c5a7
diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs
index 3c8f678b89d..b876e375daf 100644
--- a/crates/gpui2/src/element.rs
+++ b/crates/gpui2/src/element.rs
@@ -69,6 +69,24 @@ pub trait IntoElement: Sized {
self.map(|this| if condition { then(this) } else { this })
}
+ fn when_else(
+ self,
+ condition: bool,
+ then: impl FnOnce(Self) -> Self,
+ otherwise: impl FnOnce(Self) -> Self,
+ ) -> Self
+ where
+ Self: Sized,
+ {
+ self.map(|this| {
+ if condition {
+ then(this)
+ } else {
+ otherwise(this)
+ }
+ })
+ }
+
fn when_some<T>(self, option: Option<T>, then: impl FnOnce(Self, T) -> Self) -> Self
where
Self: Sized,