Rust Result Error Handling

The cluster focuses on discussions advocating for Rust's Result type (and equivalents like Haskell's Either or Swift's Result) as superior for error handling compared to exceptions, tuples, or other methods, emphasizing compiler-enforced handling and practical examples.

➡️ Stable 0.6x Programming Languages
1,892
Comments
19
Years Active
5
Top Authors
#9697
Topic ID

Activity Over Time

2008
2
2009
1
2010
2
2011
11
2012
12
2013
9
2014
68
2015
62
2016
99
2017
89
2018
81
2019
146
2020
204
2021
193
2022
221
2023
234
2024
210
2025
221
2026
29

Keywords

LBYL e.g EAFP doc.rust ErrorHandling.html Result.map MonadError swift.org lang.org OOM result rust error type haskell error handling syntax return exceptions handling

Sample Comments

troad • Aug 14, 2024 • View on HN

It sounds like you're precisely describing Rust's Result type. [0][0] https://doc.rust-lang.org/std/result/

Ericson2314 • Dec 27, 2018 • View on HN

Rust's Result or Haskell's Either are wholely better for this purpose.

foota • Aug 13, 2020 • View on HN

Rusts good support for option and result types might help here.

What's bad about locking the programmer into using Result or Option? These are enough for many common use cases, and anyway, you're free to use something else and unwrap it manually.

armchairhacker • Jan 6, 2023 • View on HN

Rust does this too with `Result::ok`

Razengan • Dec 17, 2019 • View on HN

Do you mean like Swift? (which also has a Result type)https://docs.swift.org/swift-book/LanguageGuide/ErrorHandlin...

piinbinary • Jul 14, 2017 • View on HN

I would also love Result in as a return type in place of (err, myThing)

95th • Jul 7, 2020 • View on HN

I like Rust's approach of using `Result` enum

adrusi • Dec 30, 2014 • View on HN

Check out how rust handles error composition using its Result type

Guvante • Dec 22, 2024 • View on HN

Rust leaves it unrestricted. As does Haskell (although I am lying a little most just choose to use Either for Result)Rust actually gets some use out of it, for instance returning an alternative value instead of handling it as a pure failure.