killercup / scribbles

Some notes on various topics.
https://deterministic.space
64 stars 11 forks source link

slight code error in "Elegant Library APIs" #7

Closed ConnyOnny closed 7 years ago

ConnyOnny commented 7 years ago

At "Take Closures" there is this code example:

let res: Result<i32, String> = Err("oh noes");
res.unwrap_or(42) // just returns `42`
res.unwrap_or_else(|msg| msg.len() > 12) // will call the closure

I think the > 12 part should be replaced by as i32, because the types i32 and bool don't match, making compilation impossible.

killercup commented 7 years ago

Thanks! I'll also change String to &str while I'm at it :)

(I should probably run every code block as a doc test…)