3 ms·
idk there are a lot of uses for it let dx = { let prev_x = x; x = get_x(); x - prev_x }; often, it's slightly better cpp style
by jihiggins 2y ago
idk there are a lot of uses for it
let dx = {
let prev_x = x;
x = get_x();
x - prev_x
};
often, it's slightly better cpp style scoping blocks if nothing else? there are tons of other little QoL things it enables though, but they're all going to be little ergonomics things that only seem worth it if you've used the language for awhile
- masklinn 2y agoAlso common to set up "capture clauses" for lambdas as Rust does not have that in the language, IME most common with threads: spawn({ let a = a.clone(); let b = &b; move || { // do something with the a you cloned and the b you borrowed } })