From 6474394f49b67377c9fef66f51af61f108ae3cce Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 23 Apr 2026 03:07:01 +0200 Subject: refactor(engine): remove support for multiple renderer contexts --- engine/src/util.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'engine/src/util.rs') 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 Default for MapVec } } +pub trait OptionExt +{ + /// 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( + &mut self, + func: impl Fn() -> Result, + ) -> Result<&mut T, Err>; +} + +impl OptionExt for Option +{ + fn get_or_try_insert_with_fn( + &mut self, + func: impl FnOnce() -> Result, + ) -> 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 { -- cgit v1.2.3-18-g5258