derive_more icon indicating copy to clipboard operation
derive_more copied to clipboard

TryInto with input type as error

Open Alxandr opened this issue 4 years ago • 0 comments
trafficstars

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

.....

Alxandr avatar Jul 31 '21 15:07 Alxandr