diff --git a/Cargo.toml b/Cargo.toml index 42f727f5..cc4f6bae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zproto" -version = "0.3.0" +version = "0.3.1" authors = ["Stephen Hunt "] edition = "2021" description = "A library from communicating with Zaber products in Rust." diff --git a/README.md b/README.md index befef114..c91b0454 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Add this to your `Cargo.toml: ```toml [dependencies] -zproto = "0.3.0" +zproto = "0.3.1" ``` ## Getting started @@ -66,7 +66,7 @@ By default, both the ASCII and Binary protocols are enabled via the `ascii` and ```toml [dependencies] -zproto = { version = "0.3.0", default-features = false, features = ["ascii"] } +zproto = { version = "0.3.1", default-features = false, features = ["ascii"] } ``` This will only include portions of the library related to the ASCII protocol diff --git a/src/error.rs b/src/error.rs index 29cf007b..04be601f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -70,12 +70,31 @@ macro_rules! impl_error_display { #[cfg(any(feature = "ascii", feature = "binary"))] macro_rules! impl_is_timeout { + ($name:ident) => { + paste::paste! { + impl $name { + /// A convenience function for determining if the error is due to the + /// port timing out. + /// + /// Note that a timeout error is a kind of IO error, so [`is_io`][1] will + /// also return true for timeout errors. + /// + #[doc = "[1]: " $name "::is_io"] + pub fn is_timeout(&self) -> bool { + matches!(self, $name::Io(e) if e.kind() == std::io::ErrorKind::TimedOut) + } + } + } + }; +} + +#[cfg(any(feature = "ascii", feature = "binary"))] +macro_rules! impl_is_io { ($name:ident) => { impl $name { - /// A convenience function for determining if the error is due to the - /// port timing out. - pub fn is_timeout(&self) -> bool { - matches!(self, $name::Io(e) if e.kind() == std::io::ErrorKind::TimedOut) + /// A convenience function for determining if the error is an IO error. + pub fn is_io(&self) -> bool { + matches!(self, $name::Io(_)) } } }; diff --git a/src/error/all.rs b/src/error/all.rs index ef2c5370..2c518911 100644 --- a/src/error/all.rs +++ b/src/error/all.rs @@ -69,6 +69,7 @@ error_enum! { } } impl_is_timeout! { Error } +impl_is_io! { Error } impl_from_serialport_error! { Error } impl_from_ascii_check_error! { Error { diff --git a/src/error/ascii.rs b/src/error/ascii.rs index 26eaec34..8849bbba 100644 --- a/src/error/ascii.rs +++ b/src/error/ascii.rs @@ -495,6 +495,7 @@ error_enum! { } } impl_is_timeout! { AsciiError } +impl_is_io! { AsciiError } impl_from_serialport_error! { AsciiError } impl_from_ascii_check_error! { AsciiError { diff --git a/src/error/binary.rs b/src/error/binary.rs index bf51adc5..459ab419 100644 --- a/src/error/binary.rs +++ b/src/error/binary.rs @@ -124,6 +124,7 @@ error_enum! { } } impl_is_timeout! { BinaryError } +impl_is_io! { BinaryError } impl_from_serialport_error! { BinaryError } macro_rules! define_error_codes {