Skip to content

Commit

Permalink
Simplify driver error example
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed May 27, 2023
1 parent 11528bf commit 93b175f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 47 deletions.
33 changes: 0 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ tracing-subscriber = "0.3.16"
tracing-error = "0.2.0"
color-eyre = "0.6.2"
tracing-forest = { version = "0.1.5", features = ["ansi"] }
displaydoc = "0.2.4"
enum-tag = "0.3.0"

[[bench]]
name = "image_array"
Expand Down
24 changes: 12 additions & 12 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,29 @@ impl ASCOMErrorCode {
///
/// # Example
///
/// The following example defines an error enum using [`displaydoc`] for error messages and
/// [`enum_tag`] for error codes.
///
/// ```
/// use ascom_alpaca::{ASCOMError, ASCOMErrorCode};
/// use displaydoc::Display;
/// use enum_tag::EnumTag;
/// use thiserror::Error;
///
/// #[derive(Debug, Display, EnumTag, Error)]
/// #[repr(u16)]
/// #[derive(Debug, Error)]
/// pub enum MyDriverError {
/// /// Port communication error: {0}
/// PortError(std::io::Error) = 0,
/// /// Initialization error: {0}
/// InitializationError(String) = 1,
/// #[error("Port communication error: {0}")]
/// PortError(#[from] std::io::Error),
/// #[error("Initialization error: {0}")]
/// InitializationError(String),
/// }
///
/// // this allows you to then use `my_driver.method()?` when implementing Alpaca traits
/// // and it will convert your driver error to an ASCOM error automatically
/// impl From<MyDriverError> for ASCOMError {
/// fn from(error: MyDriverError) -> Self {
/// ASCOMError::new(ASCOMErrorCode::new_for_driver(error.tag() as u16), error)
/// ASCOMError::new(
/// ASCOMErrorCode::new_for_driver(match error {
/// MyDriverError::PortError(_) => 0,
/// MyDriverError::InitializationError(_) => 1,
/// }),
/// error,
/// )
/// }
/// }
/// ```
Expand Down

0 comments on commit 93b175f

Please sign in to comment.