aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md4
-rw-r--r--mingling_core/src/asset/global_resource.rs11
-rw-r--r--mingling_macros/src/chain.rs4
3 files changed, 12 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a5cc1fc..bdfc71d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,8 +40,10 @@ fn handle_path_pick(prev: PathPick) {
}
```
-#### **BREAKING CHANGES**:
+#### **BREAKING CHANGES** (API CHANGES):
1. **\[core\]** Panic Unwind will not be supported when the `async` feature is enabled
+2. **\[core\]** `modify_res` signature changed: now returns `Return` instead of `()`
+3. **\[core\]** Renamed internal method `__modify_res_and_return_any` to `__modify_res_and_return_route`
---
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>>
diff --git a/mingling_macros/src/chain.rs b/mingling_macros/src/chain.rs
index 6e5fd64..60e44e9 100644
--- a/mingling_macros/src/chain.rs
+++ b/mingling_macros/src/chain.rs
@@ -236,7 +236,7 @@ fn generate_immut_resource_bindings<'a>(
.collect()
}
-/// Wraps the function body in nested `__modify_res_and_return_any` closures for
+/// Wraps the function body in nested `__modify_res_and_return_route` closures for
/// each mutable resource parameter. The innermost closure gets the original body,
/// and each mutable parameter wraps outward from last to first.
fn wrap_body_with_mut_resources(
@@ -252,7 +252,7 @@ fn wrap_body_with_mut_resources(
let var_name = &res.var_name;
let inner_type = &res.inner_type;
wrapped = quote! {
- ::mingling::this::<#program_type>().__modify_res_and_return_any(|#var_name: &mut #inner_type| {
+ ::mingling::this::<#program_type>().__modify_res_and_return_route(|#var_name: &mut #inner_type| {
#wrapped
}).into()
};