Stdlibcollections
pair
import std::collections::pair; · source
Pair<A, B>
type struct Pair<A, B> {
first: A;
second: B;
static new(first: A, second: B) -> Pair<A, B>;
}
An owned two-element tuple. It owns both members and drops them in declaration order. The fields are public; there are no getters.
Use it wherever you would otherwise reach for two parallel arrays or a single-purpose struct:
- Key-value entries.
Pair<Str, Config>[]is a small associative list, cheaper than aHashMapwhen the count is in the low tens and the keys need noHashimpl. - Multi-return without naming a type.
function divmod(...) -> Pair<i64, i64>. - Zipping.
Pairis the element type ofIterator::zipandIterator::enumerate, because Cryo has no heterogeneous tuple literal.
Trait implementations
implement<A, B> trait Clone for struct Pair<A, B>
where A: Clone, B: Clone
implement<A, B> trait Drop for struct Pair<A, B>
where A: Drop, B: Drop
implement<A, B> trait Eq for struct Pair<A, B>
where A: Eq, B: Eq
implement<A, B> trait Display for struct Pair<A, B>
where A: Display, B: Display // std::fmt::display
implement<A, B> trait Debug for struct Pair<A, B>
where A: Debug, B: Debug // std::fmt::display
Every impl is parametric: a Pair has it when both members do. Display renders (first, second).