Skip to content

Commit 0502c79

Browse files
committed
add destructure method for third party consumers
1 parent 8c6a3ba commit 0502c79

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

crates/bevy_mod_scripting_core/src/extractors.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,30 @@ pub struct HandlerContext<'s, P: IntoScriptPluginParams> {
151151
}
152152

153153
impl<P: IntoScriptPluginParams> HandlerContext<'_, P> {
154+
/// Splits the handler context into its individual components.
155+
///
156+
/// Useful if you are needing multiple resources from the handler context.
157+
/// Otherwise the borrow checker will prevent you from borrowing the handler context mutably multiple times.
158+
pub fn destructure(
159+
&mut self,
160+
) -> (
161+
&mut CallbackSettings<P>,
162+
&mut ContextLoadingSettings<P>,
163+
&mut Scripts,
164+
&mut RuntimeContainer<P>,
165+
&mut ScriptContexts<P>,
166+
&mut StaticScripts,
167+
) {
168+
(
169+
&mut self.callback_settings,
170+
&mut self.context_loading_settings,
171+
&mut self.scripts,
172+
&mut self.runtime_container,
173+
&mut self.script_contexts,
174+
&mut self.static_scripts,
175+
)
176+
}
177+
154178
/// Get the callback settings
155179
pub fn callback_settings(&mut self) -> &mut CallbackSettings<P> {
156180
&mut self.callback_settings

0 commit comments

Comments
 (0)