aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/asset/global_resource.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-21 20:54:05 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-21 20:54:05 +0800
commite4a4e3e2b558d771537c7a4c0ba22f0d6b541b6e (patch)
treed942e66c44cd1bf3da4ec36c508f22458a41eab3 /mingling_core/src/asset/global_resource.rs
parent021f134a3b87674be3567583c2dd04e763075f37 (diff)
Update `modify_res` to return `Return` and rename internal method
Diffstat (limited to 'mingling_core/src/asset/global_resource.rs')
-rw-r--r--mingling_core/src/asset/global_resource.rs11
1 files changed, 7 insertions, 4 deletions
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<Res>(&self, f: impl FnOnce(&mut Res))
+ pub fn modify_res<Res, Return>(&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<Res, Return>(
+ pub fn __modify_res_and_return_route<Res, Return>(
&self,
f: impl FnOnce(&mut Res) -> Return,
) -> impl Into<ChainProcess<C>>