3 ms·
That's interesting. That crate provides immutable access only and requires the fields to be trivial to copy. For example, I think there's no way for you to muta
by iudqnolq 6y ago
That's interesting. That crate provides immutable access only and requires the fields to be trivial to copy. For example, I think there's no way for you to mutate one field if you've handed out a lense to a different field.
The core problem would be you can't write something like this
fn return_part() -> &Part {
let whole = get_whole();
&whole.part
}
because whole is "dropped" at the end of the function call.
If you want to hand out parts you have to put the whole somewhere where it will stick around until you're done with the parts, and doing that nicely pretty much requires GC (you could also use lenses only in very restricted scopes or just leak memory).