From 99b0fab4f0d711ebc958e27731e2d9bcbea6ab55 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 15 May 2026 18:57:27 +0800 Subject: Add `modify` method to `ResourceMarker` trait --- CHANGELOG.md | 14 ++++++++++++++ mingling_core/src/asset/global_resource.rs | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f2c07e..6b0be09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,20 @@ fn your_chain(_prev: Prev) -> NextProcess { 9. **\[core\]** `RenderResult` now carries new data `exit_code` +10. **\[core\]** Added `modify` function to `ResourceMarker` for modifying a program's global resources + +```rust +// Example +ExitCode::modify::(|code| { + code.exit_code = 1; +}); + +// Equivalent to: +this::().modify_res::(|code| { + code.exit_code = 1; +}); +``` + #### **BREAKING CHANGES**: 1. **\[core\]** The signature of `exec` has been changed to `exec(self) -> i32` (previously was `exec(self)`) diff --git a/mingling_core/src/asset/global_resource.rs b/mingling_core/src/asset/global_resource.rs index 29d2405..8e2ce9f 100644 --- a/mingling_core/src/asset/global_resource.rs +++ b/mingling_core/src/asset/global_resource.rs @@ -4,7 +4,7 @@ use std::{ sync::{Arc, Mutex}, }; -use crate::{ChainProcess, Program, ProgramCollect}; +use crate::{ChainProcess, Program, ProgramCollect, this}; pub(crate) type GlobalResources = Arc>>>; @@ -109,9 +109,12 @@ impl AsRef for GlobalResource pub trait ResourceMarker { fn res_clone(&self) -> Self; fn res_default() -> Self; + fn modify(f: impl FnOnce(&mut Self)) + where + C: ProgramCollect + 'static; } -impl ResourceMarker for T { +impl ResourceMarker for T { fn res_clone(&self) -> Self { Clone::clone(self) } @@ -119,4 +122,11 @@ impl ResourceMarker for T { fn res_default() -> Self { Default::default() } + + fn modify(f: impl FnOnce(&mut Self)) + where + C: ProgramCollect + 'static, + { + this::().modify_res(f); + } } -- cgit