use std::error::Error;
use std::fmt::Display;
use crate::ParseError;
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum StreamError {
NoMemory,
BadXml(&'static str),
BadStream(&'static str),
}
impl Display for StreamError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
StreamError::NoMemory => write!(f, "not enough memory"),
StreamError::BadXml(msg) => write!(f, "invalid XML syntax: {msg}"),
StreamError::BadStream(msg) => write!(f, "invalid stream protocol: {msg}"),
}
}
}
impl Error for StreamError {}
impl From<ParseError> for StreamError {
fn from(err: ParseError) -> Self {
match err {
ParseError::NoMemory => StreamError::NoMemory,
ParseError::BadXml(msg) => StreamError::BadXml(msg),
}
}
}