I’m trying to write a trait that has a function which returns a mutable reference to some member in the struct that will implement the trait. Something like this:
Mojo defaults to read, so you’re taking an immutable reference to state in modify_x which means you can only borrow x immutably. Try changing it to `mut state: T`.
That won’t match the trait definition. Yes, I can get a mutable reference without a trait. The question is about how to declare functions in the trait to get mutable references to members of structs that implement the trait
+1, as Owen says this is an unpaved road in the origin system. We’re interested in improving this, but it won’t happen in the immediate future, so a workaround will be required.
Given that this does have trait conformance implications, is a way to “upcast” an origin (ex: self.x → self) something that would be reasonable to implement on a shorter timeline?