Skip to content

Commit e505d6a

Browse files
committed
Refactor AfError to impl fmt::Display instead of error::Error
1 parent 336cdba commit e505d6a

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

src/defines.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
extern crate num;
22

33
use self::num::Complex;
4-
use std::error::Error;
54
use std::fmt::Error as FmtError;
65
use std::fmt::{Display, Formatter};
76

@@ -80,13 +79,7 @@ impl Display for Backend {
8079

8180
impl Display for AfError {
8281
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
83-
write!(f, "{}", self.description())
84-
}
85-
}
86-
87-
impl Error for AfError {
88-
fn description(&self) -> &str {
89-
match *self {
82+
let text = match *self {
9083
AfError::SUCCESS => "Function returned successfully",
9184
AfError::ERR_NO_MEM => "System or Device ran out of memory",
9285
AfError::ERR_DRIVER => "Error in the device driver",
@@ -104,7 +97,8 @@ impl Error for AfError {
10497
AfError::ERR_NO_GFX => "This build of ArrayFire has no graphics support",
10598
AfError::ERR_INTERNAL => "Error either in ArrayFire or in a project upstream",
10699
AfError::ERR_UNKNOWN => "Unknown Error",
107-
}
100+
};
101+
write!(f, "{}", text)
108102
}
109103
}
110104

src/error.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ extern crate libc;
33
use self::libc::c_char;
44
use crate::defines::AfError;
55
use crate::util::{free_host, DimT, MutDimT};
6-
use std::error::Error;
76
use std::ffi::CStr;
87
use std::ops::{Deref, DerefMut};
98
use std::sync::RwLock;
@@ -39,7 +38,7 @@ pub fn handle_error_general(error_code: AfError) {
3938
AfError::SUCCESS => {} /* No-op */
4039
_ => panic!(
4140
"Error message: {}\nLast error: {}",
42-
error_code.description(),
41+
error_code,
4342
get_last_error()
4443
),
4544
}
@@ -63,7 +62,7 @@ lazy_static! {
6362
/// fn handle_error(error_code: AfError) {
6463
/// match error_code {
6564
/// AfError::SUCCESS => {}, /* No-op */
66-
/// _ => panic!("Error message: {}", error_code.description()),
65+
/// _ => panic!("Error message: {}", error_code),
6766
/// }
6867
/// }
6968
///

tests/error_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ macro_rules! implement_handler {
88
pub fn $fn_name(error_code: AfError) {
99
match error_code {
1010
AfError::SUCCESS => {} /* No-op */
11-
_ => panic!("Error message: {}", error_code.description()),
11+
_ => panic!("Error message: {}", error_code),
1212
}
1313
}
1414
};

0 commit comments

Comments
 (0)