std-method

Iterator::skip_while — skip an initial prefix

Discard items only until the first predicate failure. After that, yield remaining items without testing the predicate again. Expected stdout (not executed): [7, 0, 8] Common mistake: Expecting later matching elements to be skipped as well.

Formal Syntax & Structure

rust syntaxrust
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where Self: Sized, P: FnMut(&Self::Item) -> bool

Working Example

Example Snippetrust
fn main() {    let payload: Vec<_> = [0, 0, 7, 0, 8].into_iter().skip_while(|n| *n == 0).collect();    println!("{payload:?}");}
Rust Reference