I just came to know if let
. Just a quick question: is it right that it is – other than a match
– just to execute some side effects?
Note to self: either think before asking or drink more coffee
Of course a single if let
without an else
has to evaluate to ()
. By adding an else
one can return "proper" types, e.g.
let o = Some(42);
let y = if let Some(42) = o { "42" } else { "0" };
4 Likes