Skip to content
La3 Docs
Browse docs

Collections and Strings

Lists, maps, sets, slices, string methods, formatting, and byte conversion.

Lists

List<T> is the owned growable sequence used for runtime-sized collections.

  • push and pop mutate the list.
  • map, filter, and reduce express common transforms without manual indexing.
  • first and last return Option<T> because the list may be empty.
  • Methods that take &self or &mut self should be documented by receiver shape.
let mut log: List<str> = []
log.push("start")
log.push("done")

let upper = log.map(|s| s.to_upper())

Maps and sets

Maps store associations; sets store membership.

  • Map indexing returns a value and can fail if the key is absent.
  • get returns Option<V> and is safer for user-facing lookup.
  • Set insertion tells the reader the important fact: whether a value has already appeared.
  • Docs should prefer explicit key and value types where protocol or data-model meaning matters.

Strings

str is UTF-8 text at the language surface and an owned runtime value in native code.

  • len() returns bytes, which matters for protocols and binary formats.
  • chars() returns Unicode scalar values.
  • split, trim, replace, and case conversion are ordinary string methods.
  • as_bytes() exposes a borrowed byte view.

Formatting

F-strings should make diagnostics and examples readable without hiding formatting rules.

  • Format specs include zero-padded hex, fixed precision floats, and alignment.
  • F-strings lower to formatting primitives before backend codegen.
  • The runtime formatters must match interpreter output byte for byte.
let hex = f"0x{byte:02x}"
let pct = f"{ratio * 100:.1f}%"
let line = f"{name:>20}"