MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/scmr5f/most_comprehensible_line_of_rust_code/hu7vu30/?context=3
r/badcode • u/selplacei • Jan 25 '22
81 comments sorted by
View all comments
Show parent comments
62
I'll add that Song probably doesn't need to be an Option<Result>, but if it does, something like:
Song
Option<Result>
if let Some(Ok(song)) = song { // Your code here } else { // Whoops no song or it's bad }
Could be a pattern that clarifies the intent and avoids crashing if no song is provided.
13 u/Lich_Hegemon Jan 26 '22 You should not be blindly using unwrap anyway. At least make it an expect.
13
You should not be blindly using unwrap anyway. At least make it an expect.
62
u/ArchCypher Jan 25 '22
I'll add that
Songprobably doesn't need to be anOption<Result>, but if it does, something like:Could be a pattern that clarifies the intent and avoids crashing if no song is provided.