spatialrust_core/
runtime.rs1use crate::{DeviceKind, ExecutionPolicy};
2
3pub trait SpatialRuntime {
9 fn device_kind(&self) -> DeviceKind;
11
12 #[must_use]
14 fn supports_policy(&self, policy: ExecutionPolicy) -> bool {
15 match policy.device_kind() {
16 Some(kind) => kind == self.device_kind(),
17 None => true,
18 }
19 }
20}
21
22#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
24pub struct CpuRuntime;
25
26impl SpatialRuntime for CpuRuntime {
27 fn device_kind(&self) -> DeviceKind {
28 DeviceKind::Cpu
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use super::{CpuRuntime, SpatialRuntime};
35 use crate::{DeviceKind, ExecutionPolicy};
36
37 #[test]
38 fn cpu_runtime_accepts_cpu_and_auto_policies_only() {
39 let runtime = CpuRuntime;
40 assert_eq!(runtime.device_kind(), DeviceKind::Cpu);
41 assert!(runtime.supports_policy(ExecutionPolicy::CpuSingle));
42 assert!(runtime.supports_policy(ExecutionPolicy::CpuParallel));
43 assert!(runtime.supports_policy(ExecutionPolicy::Auto));
44 assert!(!runtime.supports_policy(ExecutionPolicy::Gpu(DeviceKind::Wgpu)));
45 }
46}