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

TryInto with input type as error #170

Closed
Alxandr opened this issue Jul 31, 2021 · 1 comment · Fixed by #220
Closed

TryInto with input type as error #170

Alxandr opened this issue Jul 31, 2021 · 1 comment · Fixed by #220
Milestone

Comments

@Alxandr
Copy link

Alxandr commented Jul 31, 2021

I have code where I use try_into to match against another enum (generated by another macro), however I need the original input value in the case that the try_into failed. I think this is much more usefull than a &'static str in general, but at least it would be nice if this could be an option. So I'd get code like this:

#[derive(TryInto)]
enum Test {
  A(A),
  B(B),
}

impl TryFrom<A> for Test {
  type Error = Test;
  fn try_from(value: Test) -> Result<Self, Test> {
    match value {
      Test::A(a) => Ok(a),
      _ => Err(value),
    }
  }
}

.....
@JelteF
Copy link
Owner

JelteF commented Dec 1, 2023

Solved in 1.0.0-beta.6 we now return a dedicated error type: https://docs.rs/derive_more/1.0.0-beta.6/derive_more/struct.TryIntoError.html

@JelteF JelteF closed this as completed Dec 1, 2023
@tyranron tyranron added this to the 1.0.0 milestone Dec 1, 2023
@tyranron tyranron reopened this Dec 1, 2023
@tyranron tyranron linked a pull request Dec 1, 2023 that will close this issue
@tyranron tyranron closed this as completed Dec 1, 2023
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

Successfully merging a pull request may close this issue.

3 participants