Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

couldn't convert the error even when it's listed as implemented #289

Open
evbo opened this issue Mar 3, 2024 · 1 comment
Open

couldn't convert the error even when it's listed as implemented #289

evbo opened this issue Mar 3, 2024 · 1 comment

Comments

@evbo
Copy link

evbo commented Mar 3, 2024

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)
}
@evbo
Copy link
Author

evbo commented Mar 4, 2024

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())
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant