1use thiserror::Error;
16
17pub type ParseResult<T> = Result<T, ParseError>;
18
19#[derive(Debug, Error)]
20pub enum ParseError {
21 #[error("EndOfStream")]
22 EndOfStream,
23 #[error("OtherParseError({0})")]
24 Other(String),
25}
26
27#[derive(Debug, Error)]
28pub enum Error {
29 #[error(transparent)]
30 Io(#[from] std::io::Error),
31 #[error("InternalError({0}")]
32 Internal(String),
33 #[error("ServerError({0})")]
34 Server(String),
35}
36
37impl From<std::string::FromUtf8Error> for ParseError {
38 fn from(e: std::string::FromUtf8Error) -> Self {
39 Self::Other(e.to_string())
40 }
41}
42
43impl From<std::num::ParseFloatError> for ParseError {
44 fn from(e: std::num::ParseFloatError) -> Self {
45 Self::Other(e.to_string())
46 }
47}
48
49impl<E: Into<ParseError>> From<E> for Error {
50 fn from(e: E) -> Self {
51 match e.into() {
52 ParseError::EndOfStream => unreachable!("EndOfStream should be handled internally."),
53 ParseError::Other(reason) => Self::Internal(reason),
54 }
55 }
56}