Skip to main content

audio_codec/
error.rs

1/// Errors returned by codec `encode_into` / `decode_into` operations.
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub enum CodecError {
4    /// The caller-provided output buffer was too small for the input.
5    BufferTooSmall,
6    /// The input data was malformed or had an unsupported length.
7    InvalidInput,
8    /// The numeric codec payload type is unknown / unsupported.
9    InvalidCodecType,
10    /// The codec name string did not match any known codec.
11    InvalidCodecName,
12    /// Codec initialisation failed (e.g. underlying library error).
13    InitFailed,
14    /// Decoding failed for an internal reason (e.g. corrupt bitstream).
15    DecodeFailed,
16    /// Encoding failed for an internal reason.
17    EncodeFailed,
18}
19
20impl core::fmt::Display for CodecError {
21    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
22        let msg = match self {
23            CodecError::BufferTooSmall => "output buffer too small",
24            CodecError::InvalidInput => "invalid input data",
25            CodecError::InvalidCodecType => "invalid codec payload type",
26            CodecError::InvalidCodecName => "invalid codec name",
27            CodecError::InitFailed => "codec initialization failed",
28            CodecError::DecodeFailed => "decode failed",
29            CodecError::EncodeFailed => "encode failed",
30        };
31        f.write_str(msg)
32    }
33}
34
35#[cfg(feature = "std")]
36impl std::error::Error for CodecError {}