use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("Platform initialization failed: {0}")]
PlatformInit(String),
#[error("No supported devices found")]
NoDevicesFound,
#[error("Device access error: {0}")]
DeviceAccess(String),
#[error("Permission denied: {0}")]
PermissionDenied(String),
#[error("Feature not supported on this platform: {0}")]
NotSupported(String),
#[error(transparent)]
Io(#[from] std::io::Error),
}
pub type Result<T> = std::result::Result<T, Error>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
let err = Error::PlatformInit("NVML not found".to_string());
assert_eq!(
err.to_string(),
"Platform initialization failed: NVML not found"
);
let err = Error::NoDevicesFound;
assert_eq!(err.to_string(), "No supported devices found");
let err = Error::DeviceAccess("GPU 0 not responding".to_string());
assert_eq!(err.to_string(), "Device access error: GPU 0 not responding");
let err = Error::PermissionDenied("Cannot access /dev/dri".to_string());
assert_eq!(err.to_string(), "Permission denied: Cannot access /dev/dri");
let err = Error::NotSupported("ANE metrics".to_string());
assert_eq!(
err.to_string(),
"Feature not supported on this platform: ANE metrics"
);
}
#[test]
fn test_error_from_io() {
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
let err: Error = io_err.into();
assert!(matches!(err, Error::Io(_)));
}
#[test]
fn test_error_is_send_sync() {
fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<Error>();
}
}