|
|
|
|
|
by puffoflogic
1241 days ago
|
|
Here's one notable use that I doubt many are familiar with: let iter = some_iterator_expression;
{iter}.nth(2)
For some reason, nth takes &mut self instead of self (note that T: Iterator => &mut T: Iterator<Item=T::Item> so there was no need for this in the API design to support having access to the iterator after exhaustion; it was a mistake). So if you tried to use it like iter.nth(2) with the non-mut binding, that would fail. But {iter} forces iter to be moved - unlike (iter) which would not. Then iter becomes a temporary and we're free to call a &mut self method on it.In general: {expression} turns a place expression into a value expression, i.e. forcing the place to be moved from. |
|