use crate::{Result, Stream};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DeviceKind {
Cpu,
Gpu,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Device {
kind: DeviceKind,
index: u32,
}
impl Device {
#[must_use]
pub const fn cpu(index: u32) -> Self {
Self { kind: DeviceKind::Cpu, index }
}
#[must_use]
pub const fn gpu(index: u32) -> Self {
Self { kind: DeviceKind::Gpu, index }
}
pub fn new_stream(self) -> Result<Stream> {
Stream::new(self)
}
pub(crate) const fn native_kind(self) -> u8 {
match self.kind {
DeviceKind::Cpu => 0,
DeviceKind::Gpu => 1,
}
}
pub(crate) fn native_index(self) -> Result<i32> {
Ok(i32::try_from(self.index)?)
}
}