mpeg_audio_header/
error.rs1use thiserror::Error;
5
6use crate::ReadPosition;
7
8#[derive(Debug, Error)]
10#[error("{} at position {:.3} ms (byte offset = {} / 0x{:X})",
11 .source, .position.duration.as_secs_f64() * 1000.0, .position.byte_offset, .position.byte_offset)]
12pub struct PositionalError {
13 #[source]
14 pub(crate) source: Error,
15
16 pub(crate) position: ReadPosition,
17}
18
19impl PositionalError {
20 #[must_use]
22 pub const fn source(&self) -> &Error {
23 &self.source
24 }
25
26 #[must_use]
28 pub const fn position(&self) -> &ReadPosition {
29 &self.position
30 }
31}
32
33impl PositionalError {
34 pub(crate) fn is_unexpected_eof(&self) -> bool {
35 self.source.is_unexpected_eof()
36 }
37}
38
39#[derive(Debug, Error)]
41#[non_exhaustive]
42pub enum Error {
43 #[error(transparent)]
45 IoError(#[from] std::io::Error),
46
47 #[error("frame error: {0}")]
48 FrameError(String),
49}
50
51impl Error {
52 fn is_unexpected_eof(&self) -> bool {
53 match self {
54 Self::IoError(err) => {
55 matches!(err.kind(), std::io::ErrorKind::UnexpectedEof)
56 }
57 _ => false,
58 }
59 }
60}