tool: Use From<T> for slightly neater error handling

This commit is contained in:
Ian Douglas Scott
2020-12-02 14:24:57 -08:00
committed by Jeremy Soller
parent 43d31ca0c3
commit 802bf417cc
3 changed files with 21 additions and 7 deletions

View File

@ -26,3 +26,17 @@ pub enum Error {
#[cfg(feature = "hidapi")]
Hid(hidapi::HidError),
}
#[cfg(feature = "std")]
impl From<std::io::Error> for Error {
fn from(error: std::io::Error) -> Self {
Self::Io(error)
}
}
#[cfg(feature = "hidapi")]
impl From<hidapi::HidError> for Error {
fn from(error: hidapi::HidError) -> Self {
Self::Hid(error)
}
}