8 ms·
Rust uses closures quite heavily. The biggest problem with UIs is that they tend to be based on inheritance, which Rust doesn't have. It's not insurmountable;
by steveklabnik 9y ago
Rust uses closures quite heavily.
The biggest problem with UIs is that they tend to be based on inheritance, which Rust doesn't have. It's not insurmountable; there are people who have written macros to make this kind of code more concise, or alternative UI libraries that don't rely on inheritance.
- amelius 9y ago> Rust uses closures quite heavily. I suppose they only support read-only free variables then?
- steveklabnik 9y agoNot exactly, no. There's a bit more ceremony since there isn't a GC, but that's a systems language for you. Closures are basically syntax sugar for a struct that represents the environment, and a function pointer which takes that struct as one of its parameters. So you can do anything that you can do with that setup, aka, anything :) https://doc.rust-lang.org/book/second-edition/ch13-01-closures.html https://doc.rust-lang.org/book/second-edition/ch13-01-closur...
- dbaupp 9y agoRust'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).