1use core::fmt;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum Error {
7 InvalidConfig(&'static str),
8 InvalidInput {
9 expected: usize,
10 actual: usize,
11 context: &'static str,
12 },
13 NeedMoreInput,
14 EndOfStream,
15 InputTooLarge {
16 capacity: usize,
17 actual: usize,
18 },
19 AllocationFailed {
20 size: usize,
21 alignment: usize,
22 },
23 EncoderError(i32),
24 DecoderError(i32),
25}
26
27impl fmt::Display for Error {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 match self {
30 Self::InvalidConfig(message) => write!(f, "invalid configuration: {message}"),
31 Self::InvalidInput {
32 expected,
33 actual,
34 context,
35 } => write!(
36 f,
37 "invalid input for {context}: expected {expected} bytes, got {actual}"
38 ),
39 Self::NeedMoreInput => write!(f, "decoder needs more input"),
40 Self::EndOfStream => write!(f, "decoder reached end of stream"),
41 Self::InputTooLarge { capacity, actual } => {
42 write!(
43 f,
44 "input too large: capacity is {capacity} bytes, got {actual}"
45 )
46 }
47 Self::AllocationFailed { size, alignment } => {
48 write!(
49 f,
50 "failed to allocate {size} bytes with alignment {alignment}"
51 )
52 }
53 Self::EncoderError(status) => {
54 write!(f, "libxaac encoder failed with status {status:#x}")
55 }
56 Self::DecoderError(status) => {
57 write!(f, "libxaac decoder failed with status {status:#x}")
58 }
59 }
60 }
61}
62
63impl std::error::Error for Error {}