Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extend from assuming a fused iterator. #150

Merged
merged 1 commit into from Jun 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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']);
}
}