Skip to content

Commit 0ea2982

Browse files
authored
Implement a conversion to RedisError from any type implementing the Error trait (#102)
This obviates the need for the list of conversions from specific error types. Unfortunately this also requires removing the conversions from `&'static str` and `String`, because future implementations may cause conflicts.
1 parent 751bbd1 commit 0ea2982

File tree

1 file changed

+2
-35
lines changed

1 file changed

+2
-35
lines changed

src/rediserror.rs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use core::num::{ParseFloatError, ParseIntError};
21
use std::fmt;
3-
use std::str::Utf8Error;
4-
use std::string::FromUtf8Error;
52

63
#[derive(Debug)]
74
pub enum RedisError {
@@ -16,38 +13,8 @@ impl RedisError {
1613
}
1714
}
1815

19-
impl From<&'static str> for RedisError {
20-
fn from(s: &'static str) -> Self {
21-
RedisError::Str(s)
22-
}
23-
}
24-
25-
impl From<String> for RedisError {
26-
fn from(s: String) -> Self {
27-
RedisError::String(s)
28-
}
29-
}
30-
31-
impl From<ParseFloatError> for RedisError {
32-
fn from(e: ParseFloatError) -> Self {
33-
RedisError::String(e.to_string())
34-
}
35-
}
36-
37-
impl From<ParseIntError> for RedisError {
38-
fn from(e: ParseIntError) -> Self {
39-
RedisError::String(e.to_string())
40-
}
41-
}
42-
43-
impl From<FromUtf8Error> for RedisError {
44-
fn from(e: FromUtf8Error) -> Self {
45-
RedisError::String(e.to_string())
46-
}
47-
}
48-
49-
impl From<Utf8Error> for RedisError {
50-
fn from(e: Utf8Error) -> Self {
16+
impl<T: std::error::Error> From<T> for RedisError {
17+
fn from(e: T) -> Self {
5118
RedisError::String(e.to_string())
5219
}
5320
}

0 commit comments

Comments
 (0)