Split some files and add more documentation
This commit is contained in:
parent
877722ed1b
commit
cd0242b796
8 changed files with 216 additions and 154 deletions
32
src/error.rs
Normal file
32
src/error.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("Device error: `{0:?}`")]
|
||||
Device(DeviceError),
|
||||
#[error("Other OBD2 error: `{0}`")]
|
||||
Other(String),
|
||||
#[error("Incorrect length (`{0}`): expected `{1}`, got `{2}`")]
|
||||
IncorrectResponseLength(&'static str, usize, usize),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DeviceError(super::device::Error);
|
||||
|
||||
impl From<super::device::Error> for Error {
|
||||
fn from(e: super::device::Error) -> Self {
|
||||
Error::Device(DeviceError(e))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::num::ParseIntError> for Error {
|
||||
fn from(e: std::num::ParseIntError) -> Self {
|
||||
Error::Other(format!("invalid data recieved: {:?}", e))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::string::FromUtf8Error> for Error {
|
||||
fn from(e: std::string::FromUtf8Error) -> Self {
|
||||
Error::Other(format!("invalid string recieved: {:?}", e))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue