From e4a4e3e2b558d771537c7a4c0ba22f0d6b541b6e Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 21 May 2026 20:54:05 +0800 Subject: Update `modify_res` to return `Return` and rename internal method --- mingling_core/src/asset/global_resource.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'mingling_core/src') diff --git a/mingling_core/src/asset/global_resource.rs b/mingling_core/src/asset/global_resource.rs index 104367a..98a8160 100644 --- a/mingling_core/src/asset/global_resource.rs +++ b/mingling_core/src/asset/global_resource.rs @@ -20,14 +20,15 @@ where } /// Modify a resource by type, applying a closure to the resource if present - pub fn modify_res(&self, f: impl FnOnce(&mut Res)) + pub fn modify_res(&self, f: impl FnOnce(&mut Res) -> Return) -> Return where Res: 'static + Default + ResourceMarker + Send + Sync, + Return: Default, { let mut guard = match self.resources.lock() { Ok(guard) => guard, Err(_) => { - return; + return Return::default(); } }; if let Some(arc_res) = guard @@ -38,14 +39,16 @@ where Ok(val) => val, Err(arc) => (*arc).res_clone(), }; - f(&mut new_res); + let r = f(&mut new_res); *arc_res = Arc::new(new_res); + return r; } + Return::default() } /// Internal syntax for the `&mut MyResource` syntax of #[chain], do not use directly #[doc(hidden)] - pub fn __modify_res_and_return_any( + pub fn __modify_res_and_return_route( &self, f: impl FnOnce(&mut Res) -> Return, ) -> impl Into> -- cgit