72 lines
1.6 KiB
Rust
72 lines
1.6 KiB
Rust
use std::{
|
|
collections::{HashMap, VecDeque},
|
|
num::ParseIntError,
|
|
str::{FromStr, Utf8Error},
|
|
};
|
|
|
|
use crate::{
|
|
element::{Content, Name, NamespaceDeclaration},
|
|
Element,
|
|
};
|
|
|
|
#[derive(Debug)]
|
|
pub enum DeserializeError {
|
|
FromStr(String),
|
|
UnexpectedAttributes(HashMap<Name, String>),
|
|
UnexpectedContent(VecDeque<Content>),
|
|
MissingAttribute(Name),
|
|
IncorrectName(String),
|
|
IncorrectNamespace(String),
|
|
Unqualified,
|
|
MissingChild,
|
|
MissingValue,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum Error {
|
|
ReadError(std::io::Error),
|
|
Utf8Error(Utf8Error),
|
|
ParseError(String),
|
|
EntityProcessError(String),
|
|
// TODO: better choice for failures than string
|
|
InvalidCharRef(String),
|
|
DuplicateNameSpaceDeclaration(NamespaceDeclaration),
|
|
DuplicateAttribute(String),
|
|
UnqualifiedNamespace(String),
|
|
MismatchedEndTag(Name, Name),
|
|
NotInElement(String),
|
|
ExtraData(String),
|
|
UndeclaredNamespace(String),
|
|
IncorrectName(Name),
|
|
UnexpectedAttribute(Name),
|
|
DeserializeError(String),
|
|
UnexpectedNumberOfContents(usize),
|
|
UnexpectedContent(Content),
|
|
UnexpectedElement(Name),
|
|
Deserialize(DeserializeError),
|
|
}
|
|
|
|
impl From<DeserializeError> for Error {
|
|
fn from(e: DeserializeError) -> Self {
|
|
Self::Deserialize(e)
|
|
}
|
|
}
|
|
|
|
impl From<std::io::Error> for Error {
|
|
fn from(e: std::io::Error) -> Self {
|
|
Self::ReadError(e)
|
|
}
|
|
}
|
|
|
|
impl From<Utf8Error> for Error {
|
|
fn from(e: Utf8Error) -> Self {
|
|
Self::Utf8Error(e)
|
|
}
|
|
}
|
|
|
|
impl From<ParseIntError> for Error {
|
|
fn from(e: ParseIntError) -> Self {
|
|
Self::InvalidCharRef(e.to_string())
|
|
}
|
|
}
|