You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm a beginner in Rust and just finished the Rustling for the first time! I have to admit that try_from_into gave me the most problems, as I was struggling with an idiomatic way to map errors with ? without repeating the lines.
Hello!
I'm a beginner in Rust and just finished the Rustling for the first time! I have to admit that
try_from_into
gave me the most problems, as I was struggling with an idiomatic way to map errors with?
without repeating the lines.I found multiple solutions, both in https://users.rust-lang.org/t/help-me-get-the-most-from-this-rustling-try-from-into-rs/62749/3 and local issues, like #816 (comment) , but all of them seemed to imply that we need to use a
Box<dyn error:Error>
, which not only is not what the exercise asks you for, but also is not possible withassert_eq!
tests, giving you the following error:The best idiomatic solution I encountered required me to write a helper function, which used
.map_err
. We could of course do it on a per-line basis, but that's repeating a lot of code. Such a solution could be found at https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f3a7d27fe7cb4c2144e8c1878086be6a , with the function in question:Does this solution cover the goal of the exercise?
Or should we, as michcia suggested on Mastodon, go along implementing
impl From<TryFromIntError> for IntoColorError
to allowtry_into
? The full playground is available at https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=13a8149fbcb5d292ac43faeed3824332 .The text was updated successfully, but these errors were encountered: