Skip to main content

wowlab_engine_ports/
spec_state.rs

1//! Opaque per-spec configuration and resettable runtime-state extension points.
2
3/// Opaque per-spec configuration owned by a spec implementation.
4pub trait SpecConfig: std::any::Any + std::fmt::Debug + Send {
5    fn as_any(&self) -> &dyn std::any::Any;
6}
7
8impl<T> SpecConfig for T
9where
10    T: std::any::Any + std::fmt::Debug + Send,
11{
12    #[inline]
13    fn as_any(&self) -> &dyn std::any::Any {
14        self
15    }
16}
17
18/// Opaque mutable per-spec state reset before every simulation iteration.
19pub trait SpecRuntime: std::any::Any + std::fmt::Debug + Send {
20    fn as_any(&self) -> &dyn std::any::Any;
21    fn as_any_mut(&mut self) -> &mut dyn std::any::Any;
22    fn reset(&mut self);
23}
24
25impl<T> SpecRuntime for T
26where
27    T: std::any::Any + std::fmt::Debug + Default + Send,
28{
29    #[inline]
30    fn as_any(&self) -> &dyn std::any::Any {
31        self
32    }
33
34    #[inline]
35    fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
36        self
37    }
38
39    #[inline]
40    fn reset(&mut self) {
41        *self = Self::default();
42    }
43}
44
45#[cfg(test)]
46#[path = "spec_state/tests.rs"]
47mod tests;