spatialrust_core/
device.rs1#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4pub enum DeviceKind {
5 #[default]
7 Cpu,
8 Wgpu,
10 Cuda,
12}
13
14impl DeviceKind {
15 #[must_use]
17 pub const fn is_cpu(self) -> bool {
18 matches!(self, Self::Cpu)
19 }
20
21 #[must_use]
23 pub const fn is_gpu(self) -> bool {
24 matches!(self, Self::Wgpu | Self::Cuda)
25 }
26}
27
28pub trait Device: core::fmt::Debug + Send + Sync + 'static {
30 fn kind(&self) -> DeviceKind;
32}
33
34#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
36#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
37pub struct CpuDevice;
38
39impl Device for CpuDevice {
40 fn kind(&self) -> DeviceKind {
41 DeviceKind::Cpu
42 }
43}