Remove first element from `&mut [T]` in-place (i.e. move start pointer)
The Rust Programming Language Forum
Remove first element from `&mut [T]` in-place (i.e. move start pointer)
This is trivial to do for non-mut slices since they are covariant, but the invariance of &mut slices is making what looks like a simple operation a little hard. Say, I have: struct Foo<'a> { bar: &'a mut [Bar], } impl<'a> Foo<'a> { fn update_and_pop_front(&mut self, bar: Bar) { if let [first, selections @ ..] = self.selections { *first = selection; // Cannot compile since we effectively have `&mut &mut [Bar]` and the lifetime // of `selections...
0 comments
No comments yet.