hydr_structures/structures/controlled_gate/snapshot/
package.rs1use super::super::ControlledGateBatch;
4use crate::structures::{GateActuatorSnapshotData, OperatingControlSnapshotData, StructureError};
5use numr::dtype::DType;
6use numr::runtime::Runtime;
7
8pub const CONTROLLED_GATE_SNAPSHOT_SCHEMA: &str = "hydr-controlled-gate-checkpoint-1";
10pub const CONTROLLED_GATE_CONTRACT_VERSION: &str = "hydr-controlled-gate-numr-cpu-1";
12
13#[derive(Clone, Debug, PartialEq)]
17pub struct ControlledGateSnapshotData {
18 pub schema: String,
20 pub contract: String,
22 pub controls: OperatingControlSnapshotData,
24 pub actuators: GateActuatorSnapshotData,
26}
27#[derive(Clone, Debug)]
29pub struct ControlledGateSnapshot<R: Runtime<DType = DType>> {
30 pub(super) batch: ControlledGateBatch<R>,
31}
32impl<R: Runtime<DType = DType>> ControlledGateSnapshot<R> {
33 pub fn time(&self) -> f64 {
35 self.batch.time()
36 }
37 pub fn data(&self) -> Result<ControlledGateSnapshotData, StructureError> {
39 self.batch.snapshot_data()
40 }
41}
42impl<R: Runtime<DType = DType>> ControlledGateBatch<R> {
43 pub fn snapshot(&self) -> ControlledGateSnapshot<R> {
45 ControlledGateSnapshot {
46 batch: self.clone(),
47 }
48 }
49 pub fn snapshot_data(&self) -> Result<ControlledGateSnapshotData, StructureError> {
51 Ok(ControlledGateSnapshotData {
52 schema: CONTROLLED_GATE_SNAPSHOT_SCHEMA.into(),
53 contract: CONTROLLED_GATE_CONTRACT_VERSION.into(),
54 controls: self.controls.snapshot_data()?,
55 actuators: self.actuators.snapshot_data()?,
56 })
57 }
58}