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 6, 2019
1 parent 19de501 commit 1c59a72
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib.rs
Expand Up @@ -1355,7 +1355,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 @@ -2311,4 +2311,16 @@ mod tests {
let decoded: SmallVec<[i32; 2]> = deserialize(&encoded).unwrap();
assert_eq!(small_vec, decoded);
}

#[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 1c59a72

Please sign in to comment.