Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Create vector of strings from array of str using from_iter

  • from_iter
fn main() {
    let animals = Vec::from_iter(
        ["mouse", "elephant", "cat", "dog", "giraffe"].map(|animal| animal.to_owned()),
    );

    println!("animals: {:?}", animals);
}
animals: ["mouse", "elephant", "cat", "dog", "giraffe"]