diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-05-15 18:57:27 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-05-15 18:57:27 +0800 |
| commit | 99b0fab4f0d711ebc958e27731e2d9bcbea6ab55 (patch) | |
| tree | ee7e7c35f356605c598398059727175b6bb51ece /mingling_core/src/asset/global_resource.rs | |
| parent | 76a2cd52acee80eed2097b777270912abf734db0 (diff) | |
Add `modify` method to `ResourceMarker` trait
Diffstat (limited to 'mingling_core/src/asset/global_resource.rs')
| -rw-r--r-- | mingling_core/src/asset/global_resource.rs | 14 |
1 files changed, 12 insertions, 2 deletions
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<Mutex<HashMap<TypeId, Box<dyn Any + Sync + Send>>>>; @@ -109,9 +109,12 @@ impl<ResType: 'static + Send + Sync> AsRef<ResType> for GlobalResource<ResType> pub trait ResourceMarker { fn res_clone(&self) -> Self; fn res_default() -> Self; + fn modify<C>(f: impl FnOnce(&mut Self)) + where + C: ProgramCollect<Enum = C> + 'static; } -impl<T: Default + Clone> ResourceMarker for T { +impl<T: Default + Clone + Send + Sync + 'static> ResourceMarker for T { fn res_clone(&self) -> Self { Clone::clone(self) } @@ -119,4 +122,11 @@ impl<T: Default + Clone> ResourceMarker for T { fn res_default() -> Self { Default::default() } + + fn modify<C>(f: impl FnOnce(&mut Self)) + where + C: ProgramCollect<Enum = C> + 'static, + { + this::<C>().modify_res(f); + } } |
