I'm seeing this trend in Rust that errors in Result
are returned like this:
fn do_something() -> Result<SomeType, Box<dyn std::error::Error>> {
// ...
}
Why are errors dynamic? Having come from a C++ background and prefering std::variant
over classical polymorphism (I'm relatively new to rust), I'm allergic to dynamic allocations, so I use them only when I really have to. I also find Rust's enums awesome to have included variants in them. Can someone please explain why isn't it standard/preferred/common to use errors as enum?