derive_more
derive_more copied to clipboard
TryInto with input type as error
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),
}
}
}
.....