Skip to content

Commit ca87231

Browse files
committed
StackVec: Remove confusion between StackVec<'a. T> and StackVec<'a, &'a mut T>
It seems that indeed, in 32ce43c, when trying to implement IntoIterator I didn't knew what I was doing and poisoned the code with StackVec<'a, &'a mut T> instead of Stack<'a, T>. Probably the lifetimes errors lead me astray. Remove the aberrant type in favor of the correct one. Signed-off-by: Eddy Petrișor <eddy.petrisor@gmail.com>
1 parent 877e763 commit ca87231

File tree

Image for: File tree

1 file changed

Image for: 1 file changed
+9
-9
lines changed

1 file changed

Image for: 1 file changed
+9
-9
lines changed

‎stack-vec/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,20 @@ impl<'a, T: Clone + 'a> StackVec<'a, T> {
129129
}
130130

131131
// FIXME: Implement `Deref`, `DerefMut`, and `IntoIterator` for `StackVec`.
132-
impl<'a, T: Clone + 'a> Deref for StackVec<'a, &'a mut T> {
133-
type Target = [&'a mut T];
132+
impl<'a, T: Clone + 'a> Deref for StackVec<'a, T> {
133+
type Target = [T];
134134

135135
fn deref(&self) -> &Self::Target {
136136
let end = self.len;
137137
&self.storage[..end]
138138
}
139139
}
140140

141-
impl<'a, T: Clone + 'a> Index<i32> for StackVec<'a, &'a mut T> {
141+
impl<'a, T: Clone + 'a> Index<usize> for StackVec<'a, T> {
142142
type Output = T;
143143

144-
fn index(&self, index: i32) -> &Self::Output {
145-
&self.storage[index as usize]
144+
fn index(&self, index: usize) -> &Self::Output {
145+
&self.storage[index]
146146
}
147147
}
148148

@@ -153,8 +153,8 @@ pub struct StackVecIntoIterator<'a, T: 'a> {
153153
index: usize,
154154
}
155155

156-
impl<'a, T: Clone + 'a> IntoIterator for StackVec<'a, &'a mut T> {
157-
type Item = &'a mut T;
156+
impl<'a, T: Clone + 'a> IntoIterator for StackVec<'a, T> {
157+
type Item = T;
158158
type IntoIter = StackVecIntoIterator<'a, T>;
159159

160160
fn into_iter(self) -> Self::IntoIter {
@@ -166,10 +166,10 @@ impl<'a, T: Clone + 'a> IntoIterator for StackVec<'a, &'a mut T> {
166166
}
167167

168168
impl<'a, T: Clone + 'a> Iterator for StackVecIntoIterator<'a, T> {
169-
type Item = &'a mut T;
169+
type Item = T;
170170

171171
fn next(&mut self) -> Option<Self::Item> {
172-
let result = self.stackvec.pop();
172+
let result = self.stackvec.pop().clone();
173173
self.index += 1;
174174

175175
result

0 commit comments

Image for: 0 commit comments
Comments
 (0)