devela/media/font/format/bdf/
error.rs1use crate::{Debug, Display, Error, FmtResult, Formatter, Version, write};
7
8#[doc = crate::_tags!(font error_composite)]
9#[doc = crate::_doc_meta!{location("media/font")}]
11#[non_exhaustive]
12#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
13pub enum BdfError {
14 UnexpectedEof {
16 line: u32,
18 },
19
20 UnexpectedDirective {
22 line: u32,
24 },
25
26 InvalidValue {
28 line: u32,
30 },
31
32 UnsupportedVersion(Version),
34}
35impl Error for BdfError {}
36impl Display for BdfError {
37 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult<()> {
38 match *self {
39 Self::UnexpectedEof { line } => {
40 write!(f, "unexpected end of BDF data at line {line}")
41 }
42 Self::UnexpectedDirective { line } => {
43 write!(f, "unexpected BDF directive at line {line}")
44 }
45 Self::InvalidValue { line } => {
46 write!(f, "invalid BDF value at line {line}")
47 }
48 Self::UnsupportedVersion(version) => {
49 write!(f, "unsupported BDF version {version}")
50 }
51 }
52 }
53}
54impl BdfError {
55 pub(crate) const fn invalid_value(line: u32) -> Self {
56 Self::InvalidValue { line }
57 }
58 pub(crate) const fn unexpected_directive(line: u32) -> Self {
59 Self::UnexpectedDirective { line }
60 }
61 pub(crate) const fn unexpected_eof(line: u32) -> Self {
62 Self::UnexpectedEof { line }
63 }
64}