Hi Rustaceans,
I'm trying to implement the From
trait for an error type:
impl From<redis::RedisError> for WebError {
fn from(err: redis::RedisError) -> Self {
WebError { original: Box::new(err), name: String::from("Redis error") }
}
}
The problem is that the Redis crate doesn't expose the RedisError
type directly. It has a types
module and then it does pub use crate::types::
in order to make the types public. So now Rust thinks that the type I need to use is redis::types::RedisError
, but I can't use it because it's in a private module and I get the following error:
error[E0277]: `?` couldn't convert the error to `errors::WebError`
--> src/lib.rs:40:53
|
40 | .query_async::<String>(&mut redis).await?;
| ^ the trait `std::convert::From<redis::types::RedisError>` is not implemented for `errors::WebError`
|
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
= help: the following implementations were found:
<errors::WebError as std::convert::From<deadpool::managed::errors::PoolError<T>>>
<errors::WebError as std::convert::From<redis::RedisError>>
= note: required by `std::convert::From::from`
Is there any way to tell Rust these are the same types? Or would it have to be patched in the redis crate?