Multiple error types

I have a function like so:

fn foo(bar: Result<String, ErrorType1>) { 
    match bar {
        Ok(x) => ...
        Err(e @ ErrorType1) { ...
        Err(e) { ...

Is there any way I can rework this to support bar being a Result type that can either be ErrorType1 or ErrorType2 and do Err(e @ ErrorType1) and Err(e @ ErrorType2) in my function?

If you want a return value that could possess multiple values, you would need to have an enum, which is a type that can represent multiple values. In your case, it would be something like

enum ErrorEnum {

If you implement From interfaces as seen in this article Error Handling - The Rust Programming Language (supposedly outdated, but I still like it), then it might make working with these errors more ergonomic.