Returning an Iterator
Jan. 3rd, 2020 10:23 amok, here's what was wrong with the previous attempt: https://stackoverflow.com/a/59576677/1935631
Declaring something as a mutable reference seems to imply that the receiver of it is the sole owner, but it doesn't work for struct fields and return values.
The expression problem - use Box. Box can be declared to contain some implementation of a trait, then at construction time you tell what that implementation is. Also, you can even add the lifetime to the signature.
Then also a closure with a reference to an immutable field - well, it used to capture a mutable reference self, not self.mx. But if you create a local variable first, then you can move that.
Declaring something as a mutable reference seems to imply that the receiver of it is the sole owner, but it doesn't work for struct fields and return values.
The expression problem - use Box. Box can be declared to contain some implementation of a trait, then at construction time you tell what that implementation is. Also, you can even add the lifetime to the signature.
Then also a closure with a reference to an immutable field - well, it used to capture a mutable reference self, not self.mx. But if you create a local variable first, then you can move that.