Skip to main content

wowlab_engine_combat/state/runtime/
config_access.rs

1use super::{CombatInstance, SpecRuntime};
2
3impl CombatInstance {
4    /// Downcast the mutable per-spec runtime state to `T`.
5    #[inline]
6    #[must_use]
7    pub fn spec_runtime<T>(&self) -> Option<&T>
8    where
9        T: SpecRuntime,
10    {
11        self.runtime
12            .spec_runtime
13            .as_ref()
14            .as_any()
15            .downcast_ref::<T>()
16    }
17
18    /// Mutable downcast of the per-spec runtime state to `T`.
19    #[inline]
20    pub fn spec_runtime_mut<T>(&mut self) -> Option<&mut T>
21    where
22        T: SpecRuntime,
23    {
24        self.runtime
25            .spec_runtime
26            .as_mut()
27            .as_any_mut()
28            .downcast_mut::<T>()
29    }
30
31    /// Replace the resettable per-spec runtime state.
32    #[inline]
33    pub fn set_spec_runtime<T>(&mut self, runtime: T)
34    where
35        T: SpecRuntime,
36    {
37        self.runtime.spec_runtime = Box::new(runtime);
38    }
39}