FlashKeepers

Rust · College · College and University

Rust IV: Collections, Iterators and Closures

Vec, HashMap, String, iterator adapters, closures, Fn traits and smart pointers like Box, Rc and RefCell.

About this set

40 basic cards for College Rust. Set 4 of 6 in Rust. It opens with "What does Vec do in Rust?" and "How do you create an empty Vec?". Study it alongside the other College sets below.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What does Vec do in Rust?
Show answerA growable, heap-allocated array type with dynamic length
How do you create an empty Vec?
Show answerVec::new() or the vec![] macro
What does Vec::with_capacity(n) do?
Show answerAllocates space for n elements without growing, starting empty
What does Vec::push() do?
Show answerAdds an element to the end of the Vec
What does Vec::pop() return?
Show answerOption<T>: Some(value) if Vec is not empty, None otherwise
What happens when you access Vec[out_of_bounds]?
Show answerThe program panics
What does Vec::get(index) return for a valid index?
Show answerSome(&element)
What does .iter() on a Vec return?
Show answerAn iterator over immutable references to elements
What does .iter_mut() on a Vec return?
Show answerAn iterator over mutable references to elements
What does .into_iter() on a Vec do?
Show answerTakes ownership and returns an iterator of moved values
What does HashMap provide?
Show answerA collection of key-value pairs with O(1) average lookup time
How do you create a HashMap?
Show answerHashMap::new() or collect() on an iterator of pairs
How do you insert a value into a HashMap?
Show answerhashmap.insert(key, value)
How do you retrieve a value from a HashMap?
Show answerhashmap.get(&key) returns Option<&V>
What does HashMap's Entry API do?
Show answerProvides efficient access to insert a value only if the key is absent

25 more cards in the app

Study this set free