Vec, HashMap, String, iterator adapters, closures, Fn traits and smart pointers like Box, Rc and RefCell.
40 cards · basic cards · AI-written, checked twice. Edit anything.
- What does Vec do in Rust?
Show answer
A growable, heap-allocated array type with dynamic length
- How do you create an empty Vec?
Show answer
Vec::new() or the vec![] macro
- What does Vec::with_capacity(n) do?
Show answer
Allocates space for n elements without growing, starting empty
- What does Vec::push() do?
Show answer
Adds an element to the end of the Vec
- What does Vec::pop() return?
Show answer
Option<T>: Some(value) if Vec is not empty, None otherwise
- What happens when you access Vec[out_of_bounds]?
Show answer
The program panics
- What does Vec::get(index) return for a valid index?
Show answer
Some(&element)
- What does .iter() on a Vec return?
Show answer
An iterator over immutable references to elements
- What does .iter_mut() on a Vec return?
Show answer
An iterator over mutable references to elements
- What does .into_iter() on a Vec do?
Show answer
Takes ownership and returns an iterator of moved values
- What does HashMap provide?
Show answer
A collection of key-value pairs with O(1) average lookup time
- How do you create a HashMap?
Show answer
HashMap::new() or collect() on an iterator of pairs
- How do you insert a value into a HashMap?
Show answer
hashmap.insert(key, value)
- How do you retrieve a value from a HashMap?
Show answer
hashmap.get(&key) returns Option<&V>
- What does HashMap's Entry API do?
Show answer
Provides efficient access to insert a value only if the key is absent