Back to course

Common Collections: Vector, String, HashMap

Rust for Systems & Web3 Security

Working with Data Groups

  1. Vector (Vec<T>): A dynamic array that can grow in size. Stored on the heap.
  2. String: A collection of bytes that can be modified. Unlike &str, it owns its data.
  3. HashMap<K, V>: Stores mapping of keys to values. Great for quick lookups (e.g., looking up a balance for a public key).

Safety Warning

Always check if a key exists in a HashMap before accessing it to avoid panics in high-security environments.