Discussion

Tell HN: My first day of Advent of Code ended with some sourness

I learned a great deal about error handling in Rust as a result, however. So I consider it a win. Here is my final commit message of the day:

fix(2019/1): avoid unwrap

unwrap() panics on error, which is not my intention.

Rather, I wish to return a generic error result.

I use the std::error:Error trait as a boxed type here, based on a thorough review of my error handling options.

The following information was helpful in identifying which options are and are not viable for error handling in Rust:

https://doc.rust-lang.org/std/result/index.html

https://doc.rust-lang.org/book/ch09-00-error-handling.html

https://blog.burntsushi.net/rust-error-handling/

https://lukaskalbertodt.github.io/2019/11/14/thoughts-on-error-handling-in-rust.html

I am disappointed that I must forgo the functional paradigm in order to properly bubble errors up to the caller.

Ignoring read/parse errors while summing lines is incorrect, in this case.

If omitting IO errors and malformed lines is acceptable, a functional style can be achieved with filter_map().

https://gitlab.com/cameronnemo/advent/commit/d3b78501d91502691d5cc6762001d4832c3bf494

6 points CameronNemo 7 years ago 4 comments

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton