use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum HalError {
NotConnected,
ConnectionFailed(String),
AlreadyConnected,
NotStreaming,
StreamError(String),
InvalidConfig(String),
DeviceError(String),
Timeout,
ChannelNotFound(String),
}
impl fmt::Display for HalError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
HalError::NotConnected => write!(f, "device not connected"),
HalError::ConnectionFailed(msg) => write!(f, "connection failed: {msg}"),
HalError::AlreadyConnected => write!(f, "device already connected"),
HalError::NotStreaming => write!(f, "streaming not active"),
HalError::StreamError(msg) => write!(f, "stream error: {msg}"),
HalError::InvalidConfig(msg) => write!(f, "invalid configuration: {msg}"),
HalError::DeviceError(msg) => write!(f, "device error: {msg}"),
HalError::Timeout => write!(f, "timeout waiting for data"),
HalError::ChannelNotFound(name) => write!(f, "channel not found: {name}"),
}
}
}
impl std::error::Error for HalError {}
pub type Result<T> = std::result::Result<T, HalError>;