1use self::response::Response;
2
3pub mod codec;
4pub mod command;
5pub mod conv;
6pub mod response;
7
8#[cfg(test)]
9pub mod fake;
10
11use thiserror::Error;
12
13#[derive(Error, Debug)]
14pub enum ProtoError {
15 #[error("I/O error: {:?}", _0)]
16 Io(#[from] std::io::Error),
17
18 #[error("Serial I/O error: {:?}", _0)]
19 Serial(#[from] tokio_serial::Error),
20
21 #[error("Command was invalid or contains syntax errors")]
22 SyntaxError,
23 #[error("Execution error")]
24 ExecutionError,
25 #[error("Connection was closed")]
26 Abort,
27 #[error("Unexpected response: {:?}", _0)]
28 Unexpected(Box<Response>),
29}
30
31impl From<Response> for ProtoError {
32 fn from(value: Response) -> Self {
33 match value {
34 Response::SyntaxError => Self::SyntaxError,
35 Response::ExecutionError => Self::ExecutionError,
36 Response::Success(_) => Self::Unexpected(value.into()),
37 Response::NoData => Self::Unexpected(value.into()),
38 }
39 }
40}
41
42pub type Result<T> = std::result::Result<T, ProtoError>;