Skip to content
Permalink
Browse files

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>
  • Loading branch information...
eddyp committed Jul 26, 2019
1 parent 877e763 commit ca87231be8aaf71932389fc0dd3fce3df46ef1b5
Showing with 9 additions and 9 deletions.
  1. +9 −9 stack-vec/src/lib.rs
@@ -129,20 +129,20 @@ impl<'a, T: Clone + 'a> StackVec<'a, T> {
}

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

fn deref(&self) -> &Self::Target {
let end = self.len;
&self.storage[..end]
}
}

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

fn index(&self, index: i32) -> &Self::Output {
&self.storage[index as usize]
fn index(&self, index: usize) -> &Self::Output {
&self.storage[index]
}
}

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

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

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

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

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

result

0 comments on commit ca87231

Please sign in to comment.
You can’t perform that action at this time.