Simplify error handling

It is nice !!

But I think it would be better anyway to use anonymous enums, because it do not enforce user type to impl From trait and much better match expression

Also anonymous enums is usable for other types as &[Error | MyError] and so on ...

2 Likes

@RustyYato @josh @pythoneer @CAD97 @Aloso @Ixrec

I have created crate https://crates.io/crates/ferris-extensions where is implemented macro that generate anonymous enum:

#[multiple_result_errors]
fn handle_file() -> Result<(), (IOError, IOError2)>
{
    get_io_error()?;
    Ok(())
}
fn main() {
    let res = handle_file();
    match res {
        Ok(t) => {},
        Err(err) => {
            match err {
                HandleFileResultErrors::IOError(err0) => {},
                HandleFileResultErrors::IOError2(err1) => {},
            };
        }
    };
}
1 Like

Some documentation would be great! Also, why is there another macro in the crate?

A major problem in implementing error handling is that the implementation must choose between a Box<dyn Error>> or a Result with an enum error. There is no good way to abstract over this distinction.

If there were an enum MaybeBox<T> that holds a T when T is Sized and holds a Box<T> when T is unsized. It would be possible to have a type like Result which can work with either approach. As far as I can tell this cannot be expressed within the type system.

Is there any way around this?

1 Like

Some times it is not possible to use Box<dyn Error>> or not desired (for example Embedded System) ... Sometime better to have anonymous enum in Result of error that can return either IOError, IOError2, KeyboardError and so on

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.