bbx_player/
error.rs

1use std::fmt;
2
3/// A specialized [`Result`] type for audio player operations.
4pub type Result<T> = std::result::Result<T, PlayerError>;
5
6/// Errors that can occur during audio playback operations.
7#[derive(Debug)]
8pub enum PlayerError {
9    /// No audio output device is available on the system.
10    NoOutputDevice,
11    /// Failed to initialize the audio output device.
12    DeviceInitFailed(String),
13    /// An error occurred during audio playback.
14    PlaybackFailed(String),
15    /// An error from the underlying audio backend (rodio or cpal).
16    BackendError(String),
17}
18
19impl fmt::Display for PlayerError {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            PlayerError::NoOutputDevice => write!(f, "No audio output device available"),
23            PlayerError::DeviceInitFailed(msg) => write!(f, "Failed to initialize audio device: {msg}"),
24            PlayerError::PlaybackFailed(msg) => write!(f, "Playback failed: {msg}"),
25            PlayerError::BackendError(msg) => write!(f, "Backend error: {msg}"),
26        }
27    }
28}
29
30impl std::error::Error for PlayerError {}