Skip to main content

elata_eeg_hal/
error.rs

1//! Error types for the HAL
2
3use std::fmt;
4
5/// Errors that can occur when working with EEG devices
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum HalError {
8    /// Device is not connected
9    NotConnected,
10    /// Device connection failed
11    ConnectionFailed(String),
12    /// Device is already connected
13    AlreadyConnected,
14    /// Streaming is not active
15    NotStreaming,
16    /// Streaming failed to start
17    StreamError(String),
18    /// Invalid configuration
19    InvalidConfig(String),
20    /// Device-specific error
21    DeviceError(String),
22    /// Timeout waiting for data
23    Timeout,
24    /// Channel not found
25    ChannelNotFound(String),
26}
27
28impl fmt::Display for HalError {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            HalError::NotConnected => write!(f, "device not connected"),
32            HalError::ConnectionFailed(msg) => write!(f, "connection failed: {msg}"),
33            HalError::AlreadyConnected => write!(f, "device already connected"),
34            HalError::NotStreaming => write!(f, "streaming not active"),
35            HalError::StreamError(msg) => write!(f, "stream error: {msg}"),
36            HalError::InvalidConfig(msg) => write!(f, "invalid configuration: {msg}"),
37            HalError::DeviceError(msg) => write!(f, "device error: {msg}"),
38            HalError::Timeout => write!(f, "timeout waiting for data"),
39            HalError::ChannelNotFound(name) => write!(f, "channel not found: {name}"),
40        }
41    }
42}
43
44impl std::error::Error for HalError {}
45
46pub type Result<T> = std::result::Result<T, HalError>;