I was trying to use take(n) on an iterator to do something with the first n items, but then do something different (a for ... in ... loop) with the remaining items.
In the declaration:
fn take(self, n: usize) -> Take<Self>
the self as first argument tells me that take() must be used on an owned value, not a reference (&self) or mutable reference (&mut self).
The documentation for by_ref() says it returns a mutable reference, and
This is useful to allow applying iterator adaptors while still retaining ownership of the original iterator.
It includes an example using by_ref().take(n), and then continuing to use the iterator (just like I wanted).
My question is, why am I allowed to call take() on a mutable reference (as opposed to requiring an owned value)? In other words, shouldn't take() have been declared something like:
fn take(&mut self, n: usize) -> Take<Self>
to make it possible to use it with a mutable reference?
What declaration should I have been looking for that would have told me this was possible?