]> git.cworth.org Git - rust-learning/commit
Switch from expect to map_err. main
authorCarl Worth <cworth@cworth.org>
Tue, 10 Mar 2026 15:08:01 +0000 (08:08 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 12 Mar 2026 04:14:58 +0000 (21:14 -0700)
commit556edb7edc52dac4280361ccbd7da3f178338350
tree211b7937bc92543a21a18e91df0f1585450d7f76
parente5b648c01829bc01c6e3b1381c2499b9ad8e3043
Switch from expect to map_err.

This lets us make a clean exit rather than triggering a panic, (which
has some extra noise and suggests something more exceptional than we
really want here).

Note our message is reworded slightly since map_err doesn't give us
full control of the string. It emits:

Error: "<our-string>"

so we don't want to start our string with "Error" as that would look
redundant.

I don't love not having full control of the error message, but still,
I think it is a reasonable compromise given how clean the code is with
.map_err.
src/main.rs