forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiB7f487c1Tahinli3 months ago659 commits

error.rs58 lines, 2.0 KiBHistoryRawDownload
1//! The crate's dependency-free error type.
2//!
3//! [`Error::Again`] and [`Error::Eof`] follow EAGAIN-style pull semantics:
4//! they are not failures. `Again` means "more input is required before output
5//! can be produced" (feed more data, then pull again); `Eof` means "the stream
6//! is finished and fully drained" (stop pulling). Everything else is a real
7//! error.
8
9/// Crate-wide result alias.
10pub type Result<T> = std::result::Result<T, Error>;
11
12/// All the ways AAC decoding/encoding can fail — or, for [`Error::Again`] /
13/// [`Error::Eof`], signal normal stream flow control.
14#[derive(Debug)]
15#[non_exhaustive]
16pub enum Error {
17 /// A code path that is scaffolded but not yet implemented. Carries a short
18 /// static label so logs point straight at the missing piece.
19 Unimplemented(&'static str),
20
21 /// End of stream — the codec has no more data to give.
22 Eof,
23
24 /// More input is required before output can be produced (codec drain/fill).
25 Again,
26
27 /// The input bytes were malformed for AAC-LC.
28 InvalidData(String),
29
30 /// A requested capability exists in concept but isn't supported here.
31 Unsupported(String),
32}
33
34impl Error {
35 /// Convenience constructor for `InvalidData` from anything string-like.
36 pub fn invalid(msg: impl Into<String>) -> Self {
37 Error::InvalidData(msg.into())
38 }
39
40 /// Convenience constructor for `Unsupported`.
41 pub fn unsupported(msg: impl Into<String>) -> Self {
42 Error::Unsupported(msg.into())
43 }
44}
45
46impl std::fmt::Display for Error {
47 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48 match self {
49 Error::Unimplemented(what) => write!(f, "not yet implemented: {what}"),
50 Error::Eof => write!(f, "end of stream"),
51 Error::Again => write!(f, "more input required"),
52 Error::InvalidData(msg) => write!(f, "invalid data: {msg}"),
53 Error::Unsupported(msg) => write!(f, "unsupported: {msg}"),
54 }
55 }
56}
57
58impl std::error::Error for Error {}