SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn my_slice_iter_mut<'iterator, T: 'iterator>(
  2.     slice: &'iterator mut [T],
  3. ) -> impl Iterator<Item = &'iterator mut T> + 'iterator {
  4.     MySliceIterMut(slice)
  5. }
  6.  
  7. struct MySliceIterMut<'iterator, T: 'iterator>(&'iterator mut [T]);
  8.  
  9. impl<'iterator, T: 'iterator> Iterator for MySliceIterMut<'iterator, T> {
  10.     type Item = &'iterator mut T;
  11.  
  12.     fn next(self: &'_ mut Self) -> Option<Self::Item> {
  13.         let slice = std::mem::replace(&mut self.0, &mut []);
  14.         let (head, tail) = slice.split_first_mut()?;
  15.         self.0 = tail;
  16.         Some(head)
  17.     }
  18. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top