diff --git a/lib.rs b/lib.rs index 2e0aa04..26d3f29 100644 --- a/lib.rs +++ b/lib.rs @@ -1356,7 +1356,7 @@ impl Extend for SmallVec { ptr::write(ptr.offset(len.get() as isize), out); len.increment_len(1); } else { - break; + return; } } } @@ -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']); + } }