murk_core/traits.rs
1//! Core abstraction traits for field access and snapshot reading.
2
3use crate::id::{FieldId, ParameterVersion, TickId, WorldGenerationId};
4
5/// Read-only access to field data within a simulation step.
6///
7/// Implemented by arena types to provide propagators with read access
8/// to field buffers. Returns `None` if the field is not readable in
9/// the current context.
10pub trait FieldReader {
11 /// Read the data for a field as a flat f32 slice.
12 ///
13 /// Returns `None` if the field ID is invalid or not readable.
14 fn read(&self, field: FieldId) -> Option<&[f32]>;
15}
16
17/// Mutable access to field data within a simulation step.
18///
19/// Implemented by arena types to provide propagators with write access
20/// to staging buffers. Returns `None` if the field is not writable in
21/// the current context.
22pub trait FieldWriter {
23 /// Get a mutable slice for writing field data.
24 ///
25 /// Returns `None` if the field ID is invalid or not writable.
26 fn write(&mut self, field: FieldId) -> Option<&mut [f32]>;
27}
28
29/// Read-only access to a published snapshot.
30///
31/// This trait decouples observation extraction (`ObsPlan`) from the
32/// arena implementation. `ObsPlan` reads through `&dyn SnapshotAccess`
33/// rather than referencing `ReadArena` directly (Decision N).
34pub trait SnapshotAccess {
35 /// Read field data from the snapshot.
36 ///
37 /// Returns `None` if the field ID is invalid or not present.
38 fn read_field(&self, field: FieldId) -> Option<&[f32]>;
39
40 /// The tick at which this snapshot was produced.
41 fn tick_id(&self) -> TickId;
42
43 /// The arena generation of this snapshot.
44 fn world_generation_id(&self) -> WorldGenerationId;
45
46 /// The parameter version at the time of this snapshot.
47 fn parameter_version(&self) -> ParameterVersion;
48}