It makes fields
immutable again.
fields
was previously defined as mutable (let mut fields = …;
), to be used with sort_by_key
which sorts in-place and requires the target to be mutable. The author has chosen here to explicitly prevent further mutability.
"Downgrading" a mutable binding to immutable is quite common in Rust.
Another common way to do this is to use a block expression:
let fields = {
let mut fields = …;
fields.sort_by_key(…);
fields
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…