summaryrefslogtreecommitdiff
path: root/engine/src/util.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-04-23 03:07:01 +0200
committerHampusM <hampus@hampusmat.com>2026-04-23 03:07:01 +0200
commit6474394f49b67377c9fef66f51af61f108ae3cce (patch)
tree60acc11667e315c3226dac82f130361bbec5a834 /engine/src/util.rs
parent7699a1f498dd41d9abfc907d36e37dfed7a761c0 (diff)
refactor(engine): remove support for multiple renderer contextsHEADmaster
Diffstat (limited to 'engine/src/util.rs')
-rw-r--r--engine/src/util.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/engine/src/util.rs b/engine/src/util.rs
index 0c81c71..f18a9c7 100644
--- a/engine/src/util.rs
+++ b/engine/src/util.rs
@@ -68,6 +68,32 @@ impl<Key: Ord, Value> Default for MapVec<Key, Value>
}
}
+pub trait OptionExt<T>
+{
+ /// Substitute for the currently experimental function
+ /// [`Option::get_or_try_insert_with`].
+ /// See https://github.com/rust-lang/rust/issues/143648
+ fn get_or_try_insert_with_fn<Err>(
+ &mut self,
+ func: impl Fn() -> Result<T, Err>,
+ ) -> Result<&mut T, Err>;
+}
+
+impl<T> OptionExt<T> for Option<T>
+{
+ fn get_or_try_insert_with_fn<Err>(
+ &mut self,
+ func: impl FnOnce() -> Result<T, Err>,
+ ) -> Result<&mut T, Err>
+ {
+ if let None = self {
+ *self = Some(func()?);
+ }
+
+ Ok(unsafe { self.as_mut().unwrap_unchecked() })
+ }
+}
+
macro_rules! try_option {
($expr: expr) => {
match $expr {