On 24/06/12 19:51, Niko Matsakis wrote:
Are there other ways of fixing the issue?
There is one other way. You can restructure the caller. The most
ambitious would be to change the field from mutable to immutable, but
often that does not work. In that case, you can also update the type
of the record from @{mut f: option<T>} to @{mut f: @option<T>}. You
would then call the function with `*r.f` (where `r` is the record).
This is permitted because, while the `f` field is mutable, the field
does not store the option but rather a pointer to the option. The
*option itself* is stored in immutable memory (that is, the @ box).
This means putting wrapping every mutable field *of a type not passed by
value* inside a shared box (because every mutable field might need
passing to a function). This means that updating the field requires
memory allocation, and reading the field requires following a pointer
indirection. This seems disproportionately expensive.
If these concerns are real (I think they are but I don't that much about
rust) then surely there is a better solution?
Gareth
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev