The Missing Piece in Rust Error Handling

9 days ago by SorteKanin to c/rust

Rust already has most of what I want from error handling: explicit control flow, errors as values, and concise propagation with ?. The friction comes when deciding what to put in the error half of Result. We often end up choosing between precise types that require boilerplate and convenient types that hide which errors can occur. But precision and convenience do not have to be competing goals. Error types should compose as easily as the functions that return them.
SorteKanin 13 points 9 days ago

So basically their argument is that the missing piece is anonymous sum types. I tend to agree! It would be amazing to have that as a language feature, i.e. Result<(), FooError | BarError>. Unfortunately that is unlikely to arrive to the language for a loooong time... But I think I will definitely try out this library in the meantime.

path: 0 26205544, hotness: undefined, score: 13, children: 3
BB_C 3 points 9 days ago

A language feature is not needed because macros exist.

I would even argue that perhaps the most important role macros play is blocking adding endless language features 😉

path: 0 26205544 26217927, hotness: undefined, score: 3, children: 2
SorteKanin 2 points 9 days ago

Macros are often not very ergonomical to use compared to language features.

Also, why anonymous product types but not anonymous sum types? It seems kind of weird to me. Anonymous sum types can be just as useful as anonymous product types, as the blog post illustrates quite well I think.

path: 0 26205544 26217927 26218295, hotness: undefined, score: 2, children: 1
BB_C 2 points 8 days ago

The language wouldn't have lost much without tuples actually. But they do at least have direct pattern destructuring utility. Anonymous enums don't.

They also don't pose potential future awkwardness if/when variant types become a thing.

path: 0 26205544 26217927 26218295 26220675, hotness: undefined, score: 2, children: 0
FizzyOrange 9 points 9 days ago

Interesting. I'm surprised that it's possible to use tuples like that. Might try this.

path: 0 26205718, hotness: undefined, score: 9, children: 0
Ephera 4 points 9 days ago

Damn, this looks like it might solve my pain points with error handling. Will have to see, if it replaces them with new pain points, since error handling is fundamentally hard, but at least, it isn't starting completely from scratch...

path: 0 26207265, hotness: undefined, score: 4, children: 0
rust
rust

@programming.dev

login for more options
8328
1423
338

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits
  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

go to feed...