
Tell HN: My first day of Advent of Code ended with some sourness - CameronNemo
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:<p>fix(2019&#x2F;1): avoid unwrap<p>unwrap() panics on error, which is not my intention.<p>Rather, I wish to return a generic error result.<p>I use the std::error:Error trait as a boxed type here,
based on a thorough review of my error handling options.<p>The following information was helpful in identifying which
options are and are not viable for error handling in Rust:<p>https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;result&#x2F;index.html<p>https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;book&#x2F;ch09-00-error-handling.html<p>https:&#x2F;&#x2F;blog.burntsushi.net&#x2F;rust-error-handling&#x2F;<p>https:&#x2F;&#x2F;lukaskalbertodt.github.io&#x2F;2019&#x2F;11&#x2F;14&#x2F;thoughts-on-error-handling-in-rust.html<p>I am disappointed that I must forgo the functional paradigm
in order to properly bubble errors up to the caller.<p>Ignoring read&#x2F;parse errors while summing lines is incorrect,
in this case.<p>If omitting IO errors and malformed lines is acceptable,
a functional style can be achieved with filter_map().<p>https:&#x2F;&#x2F;gitlab.com&#x2F;cameronnemo&#x2F;advent&#x2F;commit&#x2F;d3b78501d91502691d5cc6762001d4832c3bf494
======
sophiebits
Can you not use the question mark operator inside the .map() callback to
return a Result, something like this answer?

[https://stackoverflow.com/a/26370894/49485](https://stackoverflow.com/a/26370894/49485)

(Not a Rust expert.)

~~~
CameronNemo
This is exactly what I was missing... thank you!

------
w4tson
Not a Rust expert. Here are my solutions

[https://github.com/w4tson/advent-of-
code-2019/blob/master/da...](https://github.com/w4tson/advent-of-
code-2019/blob/master/day01/src/main.rs)

------
username90
The functional solution would be to parse the line in one .map statement and
apply the formula in the next, not doing both in the same. Then you get more
options for handling errors, like filtering between the map statements or
bubbling them from there.

