3 ms·
Rust's borrow checker makes writing to captured variables okay and safe, e.g. this is a bit unconventional, but it works: let mut sum = 0; (0..10).for_each
by dbaupp 9y ago
Rust's borrow checker makes writing to captured variables okay and safe, e.g. this is a bit unconventional, but it works:
let mut sum = 0;
(0..10).for_each(|i| sum += i);
println!("{}", sum); // 45
Having cyclic values and/or mutation of shared values requires things like reference counting and cells, but this is what designed-for-UI languages like Swift are doing, just with more syntactic sugar (and, of course, the lack of it in Rust is still annoying for this sort of thing, but it isn't a fundamental blocker, and is less problematic than lack of inheritance, as steveklabnik says).