Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've found success in such cases by splitting the struct in question. This example is a bit contrived, but you could do something like:

    self.counter.inc();
Where `self.counter` is a new struct that holds `x`. Because `counter` is its own struct field, I can call mutable methods on it while holding mutable references to other fields.

What I've found is that often the current "object" naturally decomposes into different parts each of which can have their own methods that only need to work with their particular subset of the fields.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: