Skip to content

Commit

Permalink
Fix extend from assuming a fused iterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jun 7, 2019
1 parent f96322b commit 1fbaf10
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib.rs
Expand Up @@ -1356,7 +1356,7 @@ impl<A: Array> Extend<A::Item> for SmallVec<A> {
ptr::write(ptr.offset(len.get() as isize), out);
len.increment_len(1);
} else {
break;
return;
}
}
}
Expand Down Expand Up @@ -2329,4 +2329,16 @@ mod tests {
v.push(4);
assert_eq!(v[..], [4]);
}

#[test]
fn resumable_extend() {
let s = "a b c";
// This iterator yields: (Some('a'), None, Some('b'), None, Some('c')), None
let it = s
.chars()
.scan(0, |_, ch| if ch.is_whitespace() { None } else { Some(ch) });
let mut v: SmallVec<[char; 4]> = SmallVec::new();
v.extend(it);
assert_eq!(v[..], ['a']);
}
}

0 comments on commit 1fbaf10

Please sign in to comment.