if let Channel::Stable(v) = release_info()
&& let Semver { major, minor, .. } = v
&& major == 1
&& minor == 88
{
println!("`let_chains` was stabilized in this version");
}
I assume without the chains this would be
if let Channel::Stable(v) = release_info(){
if let let Semver { major, minor, .. } = v {
if major == 1 && minor == 88 {
println!("`let_chains` was stabilized in this version");
}
}
}
Let chains are a cool feature, even if that wasn't the best demonstration. Check out the diff in this PR[1] for some more real-world examples, where you bind some variable in the let and then call methods and/or do dynamic comparisons with those variables in the chain.
if let Some(host_clause) = assumption.as_host_effect_clause()
&& host_clause.def_id() == goal.predicate.def_id()
&& host_clause.constness().satisfies(goal.predicate.constness)
And TBF even this could be rewritten to avoid nesting without let chain, given enough mapping and whatnot on the RHS. But I wouldn't have -- whereas with the original example, I would have written it like I showed, and probably still would.
Yeah, it's a judgement call which is nicer for a given piece of code, and it's true that the pattern itself does nest in my version too.[1] I've definitely used multiple let something = ...; let something = ...; statements to break up awkward nesting and method chains pre 1.88, and I imagine working with let chaining will lead to analogous code, such as in your original example.
Though the if [let] blocks don't, which is what the notes talk about. ↩︎