thiserror
thiserror copied to clipboard
couldn't convert the error even when it's listed as implemented
How can strum::ParseError be "not implemented" if it's part of "the following other types" that are implemented?:
error[E0277]: `?` couldn't convert the error to `CustomError`
--> src/operation.rs:107:47
|
107 | let name = CustomName::from_str(name)?;
| ^ the trait `From<strum::ParseError>` is not implemented for `CustomError`
|
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
= help: the following other types implement trait `From<T>`:
<CustomError as From<strum::ParseError>>
= note: required for `Result<std::option::Option<CustomStuff>, CustomError>` to implement `FromResidual<Result<Infallible, strum::ParseError>>`
It is only an issue if I add AsRefStr derive from strum:
#[derive(Error, Debug, AsRefStr)]
pub enum CustomError {
#[error(transparent)]
Strum(#[from] strum::ParseError)
}
I can manually implement it though and it works without collision:
impl From<strum::ParseError> for CustomError {
fn from(e: strum::ParseError) -> Self {
CustomError::Invalid(e.to_string())
}
}
Hi @evbo, sorry that no one was able to provide guidance here. If this is still an issue, you could try taking this question to any of the resources shown in https://www.rust-lang.org/community. Thiserror is one of the most widely used Rust libraries so plenty of people will be able to help explain whatever was going on.