Skip to content

Commit

Permalink
Move from failure to thiserror
Browse files Browse the repository at this point in the history
Addresses issue deviceplug#48
  • Loading branch information
stygian-coffee authored and qdot committed Feb 4, 2021
1 parent 838d220 commit abe899f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ num = "0.3.1"
log = "0.4.13"
enum_primitive = "0.1.1"
bitflags = "1.2.1"
failure = "0.1.8"
failure_derive = "0.1.8"
thiserror = "1.0.23"
backtrace = "0.3.55"
async-std = "1.9.0"
uuid = "0.8.2"
Expand Down
13 changes: 7 additions & 6 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use std::{
fmt::{self, Debug, Display, Formatter},
str::FromStr,
};
use thiserror::Error;

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -94,11 +95,11 @@ impl Debug for BDAddr {

type ParseBDAddrResult<T> = std::result::Result<T, ParseBDAddrError>;

#[derive(Debug, Fail, Clone, PartialEq)]
#[derive(Debug, Error, Clone, PartialEq)]
pub enum ParseBDAddrError {
#[fail(display = "Bluetooth address has to be 6 bytes long")]
#[error("Bluetooth address has to be 6 bytes long")]
IncorrectByteCount,
#[fail(display = "Malformed integer in Bluetooth address")]
#[error("Malformed integer in Bluetooth address")]
InvalidInt,
}

Expand Down Expand Up @@ -192,11 +193,11 @@ impl From<ParseUUIDError> for Error {
}
}

#[derive(Debug, Fail, Clone, PartialEq)]
#[derive(Debug, Error, Clone, PartialEq)]
pub enum ParseUUIDError {
#[fail(display = "UUID has to be either 2 or 16 bytes long")]
#[error("UUID has to be either 2 or 16 bytes long")]
IncorrectByteCount,
#[fail(display = "Malformed integer in UUID")]
#[error("Malformed integer in UUID")]
InvalidInt,
}

Expand Down
18 changes: 8 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ extern crate num;
#[macro_use]
extern crate bitflags;

extern crate failure;
#[macro_use]
extern crate failure_derive;
extern crate thiserror;

use std::result;
use std::time::Duration;
Expand All @@ -124,24 +122,24 @@ pub mod corebluetooth;
#[cfg(target_os = "windows")]
pub mod winrtble;

#[derive(Debug, Fail, Clone)]
#[derive(Debug, thiserror::Error, Clone)]
pub enum Error {
#[fail(display = "Permission denied")]
#[error("Permission denied")]
PermissionDenied,

#[fail(display = "Device not found")]
#[error("Device not found")]
DeviceNotFound,

#[fail(display = "Not connected")]
#[error("Not connected")]
NotConnected,

#[fail(display = "The operation is not supported: {}", _0)]
#[error("The operation is not supported: {}", _0)]
NotSupported(String),

#[fail(display = "Timed out after {:?}", _0)]
#[error("Timed out after {:?}", _0)]
TimedOut(Duration),

#[fail(display = "{}", _0)]
#[error("{}", _0)]
Other(String),
}

Expand Down

0 comments on commit abe899f

Please sign in to comment.