1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
pub trait MoveTo {
    fn move_to(&mut self, pos: usize);
}

impl<'a, T: 'a, A: Allocator> MoveTo for std::collections::linked_list::CursorMut<'a, T, A> {
    fn move_to(&mut self, pos: usize) {
        let diff = self.index().unwrap() as isize - pos as isize;
        if diff == 0 {
            return;
        } else if diff < 0 {
            for _ in 0..diff {
                self.move_next()
            }
        } else {
            for _ in diff..0 {
                self.move_prev()
            }
        }

        assert_eq!(self.index().unwrap(), pos)
    }
}