std-method

Iterator::chain

Read one source followed by another source with the same item type. This does not require joining collections first. Expected stdout (not executed): [1, 2, 8, 9] Common mistake: Expecting chain to alternate between sources.

Formal Syntax & Structure

rust syntaxrust
fn chain<U: IntoIterator<Item = Self::Item>>(self, other: U) -> Chain<Self, U::IntoIter> where Self: Sized

Working Example

Example Snippetrust
fn main() {    let ids: Vec<_> = (1..3).chain(8..10).collect();    println!("{ids:?}");}
Rust Reference