ADR-384: Entry::or_default and Seq::cloned Are in std

Status: Accepted (#1082) Date: October 31, 2026 (architect’s decision under the owner’s rule of 2026-10-31, docs/supervisor.md, Language decisions: an obvious std counterpart of a Rust call is the architect’s) Answers: two Rust calls the C1a move (contracts/mod.rs) needs and std lacks: .entry(k).or_default() and iter().cloned() (both NK1171 today) Related: ADR-collections-1 (the maps’ entries, D4 the copy of each element), ADR-282 D7/D9 (.clone() is the program’s copy), Part III 17.1 (std::collections, Seq[T]), Part III 17 (every Rust std call a move moves has a counterpart)

1. Question

The C1a move wrote or_insert_with(fn() { collections::BTreeSet() }) for Rust’s or_default() and .map(fn(p) { p.clone() }) for .cloned(). Both are ways around a missing entry (CLAUDE.md, A missing form stops the work). Are the two entries in std, and what do they mean?

2. Decision

D1 - Entry::or_default() puts in the value made with no arguments

m.entry(k).or_default() is m.entry(k).or_insert_with(fn { V() }): the value that is there, putting in first the one that V() makes where there is none. It is on both maps, as or_insert_with is (ADR-collections-1). It is offered where V can be made with no arguments: a collection, String (empty), a number (0), bool (false), and a struct every field of which has a default. For another V the call is refused, with the code that refuses a call whose type does not fit (no new code); its help names or_insert_with. It runs nothing of the program’s, so it never pauses (sync = true).

D2 - Seq::cloned() hands on a copy of each element

xs.iter().cloned() is xs.iter().map fn(x) { x.clone() }: a sequence of owned T, each element the program’s copy (ADR-282 D7), as s.extend(xs.clone()) copies each element (ADR-collections-1 D4). On a sequence whose elements are views it lowers to Rust’s cloned(); on one whose elements are already owned, to the map it means, or to nothing where the compiler knows nothing else holds them. It passes sync, pauses, throws, ends and sized through as map does.

3. Why (the principles)

4. Not decided here

copied (one word is enough, D2); Option::cloned (no move has met it).

This site is open source. Improve this page.