Rust and Cargo 1 · Code patterns

Use a HashMap

Insert values and read them back.

use std::collections::HashMap;

let mut scores = HashMap::new();
scores.insert("ada", 10);
let score = scores.get("ada").copied().unwrap_or(0);

Official Rust and Cargo 1 documentation

More code patterns commands

All code patterns commands · Rust and Cargo 1 cheatsheet

Was this page helpful?