Closed
Description
I can access a &mut int
through a & &mut int
pointer:
let x = &mut ~3; let y = &x; ***y // evaluates to `3`
But not access a &mut
struct field through &self
:
struct Ref<'self, T>(&'self mut T);
let mut it = range(0,3);
let r = &Ref(&mut it);
r.size_hint()
// error: cannot borrow an `&mut` in a `&` pointer; try an `&mut` instead
The use case is precisely Ref
above, in essence, I want to implement a "by-ref" (by mutable ref) adaptor for iterators. And it works fine for implementing Iterator::next
but not for Iterator::size_hint
for the reason above.