Skip to content
CryoCryo home
Stdlibcollections

pair

import std::collections::pair; · source

Types

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 a HashMap when the count is in the low tens and the keys need no Hash impl.
  • Multi-return without naming a type. function divmod(...) -> Pair<i64, i64>.
  • Zipping. Pair is the element type of Iterator::zip and Iterator::enumerate, because Cryo has no heterogeneous tuple literal.

Properties

PropertyType
firstA
secondB

Constructors

static new(first: A, second: B) -> Pair<A, B>;

Construct a pair from its two members. Both are moved in by value; if a member owns heap state, that ownership transfers to the pair and will be released when the pair itself is dropped.

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>
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).