1pub trait DiffHook: Sized {
4 type Error;
6
7 fn equal(&mut self, old_index: usize, new_index: usize, len: usize) -> Result<(), Self::Error> {
11 let _ = old_index;
12 let _ = new_index;
13 let _ = len;
14 Ok(())
15 }
16
17 fn delete(
20 &mut self,
21 old_index: usize,
22 old_len: usize,
23 new_index: usize,
24 ) -> Result<(), Self::Error> {
25 let _ = old_index;
26 let _ = old_len;
27 let _ = new_index;
28 Ok(())
29 }
30
31 fn insert(
34 &mut self,
35 old_index: usize,
36 new_index: usize,
37 new_len: usize,
38 ) -> Result<(), Self::Error> {
39 let _ = old_index;
40 let _ = new_index;
41 let _ = new_len;
42 Ok(())
43 }
44
45 #[inline(always)]
55 fn replace(
56 &mut self,
57 old_index: usize,
58 old_len: usize,
59 new_index: usize,
60 new_len: usize,
61 ) -> Result<(), Self::Error> {
62 self.delete(old_index, old_len, new_index)?;
63 self.insert(old_index, new_index, new_len)
64 }
65
66 #[inline(always)]
68 fn finish(&mut self) -> Result<(), Self::Error> {
69 Ok(())
70 }
71}
72
73impl<'a, D: DiffHook + 'a> DiffHook for &'a mut D {
74 type Error = D::Error;
75
76 #[inline(always)]
77 fn equal(&mut self, old_index: usize, new_index: usize, len: usize) -> Result<(), Self::Error> {
78 (*self).equal(old_index, new_index, len)
79 }
80
81 #[inline(always)]
82 fn delete(
83 &mut self,
84 old_index: usize,
85 old_len: usize,
86 new_index: usize,
87 ) -> Result<(), Self::Error> {
88 (*self).delete(old_index, old_len, new_index)
89 }
90
91 #[inline(always)]
92 fn insert(
93 &mut self,
94 old_index: usize,
95 new_index: usize,
96 new_len: usize,
97 ) -> Result<(), Self::Error> {
98 (*self).insert(old_index, new_index, new_len)
99 }
100
101 #[inline(always)]
102 fn replace(
103 &mut self,
104 old: usize,
105 old_len: usize,
106 new: usize,
107 new_len: usize,
108 ) -> Result<(), Self::Error> {
109 (*self).replace(old, old_len, new, new_len)
110 }
111
112 #[inline(always)]
113 fn finish(&mut self) -> Result<(), Self::Error> {
114 (*self).finish()
115 }
116}
117
118pub struct NoFinishHook<D: DiffHook>(D);
123
124impl<D: DiffHook> NoFinishHook<D> {
125 pub fn new(d: D) -> NoFinishHook<D> {
127 NoFinishHook(d)
128 }
129
130 pub fn into_inner(self) -> D {
132 self.0
133 }
134}
135
136impl<D: DiffHook> DiffHook for NoFinishHook<D> {
137 type Error = D::Error;
138
139 #[inline(always)]
140 fn equal(&mut self, old_index: usize, new_index: usize, len: usize) -> Result<(), Self::Error> {
141 self.0.equal(old_index, new_index, len)
142 }
143
144 #[inline(always)]
145 fn delete(
146 &mut self,
147 old_index: usize,
148 old_len: usize,
149 new_index: usize,
150 ) -> Result<(), Self::Error> {
151 self.0.delete(old_index, old_len, new_index)
152 }
153
154 #[inline(always)]
155 fn insert(
156 &mut self,
157 old_index: usize,
158 new_index: usize,
159 new_len: usize,
160 ) -> Result<(), Self::Error> {
161 self.0.insert(old_index, new_index, new_len)
162 }
163
164 #[inline(always)]
165 fn replace(
166 &mut self,
167 old_index: usize,
168 old_len: usize,
169 new_index: usize,
170 new_len: usize,
171 ) -> Result<(), Self::Error> {
172 self.0.replace(old_index, old_len, new_index, new_len)
173 }
174
175 fn finish(&mut self) -> Result<(), Self::Error> {
176 Ok(())
177 }
178}