bbx_core/
error.rs

1//! Error types for the bbx_audio workspace.
2//!
3//! This module provides a C-compatible error enum and a Result type alias
4//! for use across all crates in the workspace.
5
6use std::fmt;
7
8/// Error codes for bbx_audio operations.
9///
10/// Uses `#[repr(C)]` for C-compatible memory layout, enabling FFI usage.
11#[repr(C)]
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
13pub enum BbxError {
14    /// No error occurred.
15    Ok = 0,
16    /// A null pointer was passed where a valid pointer was expected.
17    NullPointer = 1,
18    /// An invalid parameter value was provided.
19    InvalidParameter = 2,
20    /// An invalid buffer size was specified.
21    InvalidBufferSize = 3,
22    /// The graph has not been prepared for playback.
23    GraphNotPrepared = 4,
24    /// Memory allocation failed.
25    AllocationFailed = 5,
26}
27
28impl fmt::Display for BbxError {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            BbxError::Ok => write!(f, "no error"),
32            BbxError::NullPointer => write!(f, "null pointer"),
33            BbxError::InvalidParameter => write!(f, "invalid parameter"),
34            BbxError::InvalidBufferSize => write!(f, "invalid buffer size"),
35            BbxError::GraphNotPrepared => write!(f, "graph not prepared"),
36            BbxError::AllocationFailed => write!(f, "allocation failed"),
37        }
38    }
39}
40
41impl std::error::Error for BbxError {}
42
43/// Result type alias for bbx_audio operations.
44pub type Result<T> = std::result::Result<T, BbxError>;