nettext/src/enc/error.rs

24 lines
839 B
Rust
Raw Normal View History

2022-11-18 13:15:30 +00:00
use std::fmt;
/// An error that happenned when creating a nettext encoder term
#[derive(Debug)]
pub enum Error {
InvalidCharacter(u8),
InvalidRaw,
NotADictionnary,
2022-11-18 17:59:06 +00:00
DuplicateKey(String),
2022-11-18 13:15:30 +00:00
ListInList,
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::InvalidCharacter(c) => write!(f, "Invalid character '{}'", *c as char),
Error::InvalidRaw => write!(f, "Invalid RAW nettext litteral"),
Error::NotADictionnary => write!(f, "Tried to insert into a term that isn't a dictionnary"),
2022-11-18 17:59:06 +00:00
Error::DuplicateKey(s) => write!(f, "Duplicate dict key: {}", s),
2022-11-18 13:15:30 +00:00
Error::ListInList => write!(f, "Refusing to build nested lists with list(), use either list_flatten() or list_nested()"),
}
}
}