docchi_core/imp/structs/
linked_map_iter_mut.rs

1use crate::imp::structs::linked_map_unsafe_iter::LinkedMapUnsafeIter;
2use std::marker::PhantomData;
3use crate::imp::structs::linked_m::{LinkedMap, MutNode};
4
5pub struct LinkedMapIterMut<'a, V>{
6    iter : LinkedMapUnsafeIter<V>,
7    phantom : PhantomData<&'a LinkedMap<V>>,
8}
9impl<'a, V> LinkedMapIterMut<'a, V>{
10    pub(crate) fn new(map : &'a mut LinkedMap<V>, node : *mut MutNode<V>) -> LinkedMapIterMut<'a, V>{
11        LinkedMapIterMut{ iter : LinkedMapUnsafeIter::new(map, node), phantom : PhantomData::default() }
12    }
13
14    ///現在のカーソルにあるアイテムを返し、カーソルを進める
15    pub fn next(&mut self) -> Option<(&'a u64, &'a mut V)> {
16        self.iter.next_mut()
17    }
18
19    // ///前に戻ることが出来る。そして元あった場所を削除し、それによって削除されたアイテムの次にあったアイテムが現在のカーソルの次にくるので、
20    // /// next2回でそれをとることも出来る。Cインターフェースやunsafe iterなら
21    // ///今ある場所をremoveしたらポインタが不正になって安全にnext/prevできない
22    // pub fn prev(&mut self) -> Option<(&'a u64, &'a mut V)> {
23    //     self.iter.prev_mut()
24    // }
25    //
26    // pub fn current(&mut self) -> Option<(&'a u64, &'a mut V)> {
27    //     self.iter.current_mut()
28    // }
29
30    ///nextもprevも現在のカーソルにあるアイテムを返す
31    ///空であるか、最後/最初まで移動してアイテムが無くなったらfalse
32    pub fn is_available(&self) -> bool {
33        self.iter.is_available()
34    }
35    pub fn is_first(&self) -> bool {
36        self.iter.is_first()
37    }
38    pub fn is_last(&self) -> bool {
39        self.iter.is_first()
40    }
41}
42impl<'a,V> Iterator for LinkedMapIterMut<'a, V>{
43    type Item = (&'a u64, &'a mut V);
44
45    fn next(&mut self) -> Option<Self::Item> {
46        self.next()
47    }
48}
49
50impl<'a,V> IntoIterator for &'a mut LinkedMap<V>{
51    type Item = (&'a u64, &'a mut V);
52    type IntoIter = LinkedMapIterMut<'a, V>;
53
54    fn into_iter(self) -> Self::IntoIter {
55        self.iter_mut()
56    }
57}