---
title: "Built-in methods"
url: https://una-lang.org/en/docs/std/builtin/
release: v0.4.0
source: https://github.com/una-lang/una/blob/v0.4.0/docs/std/builtins.json
---

# Built-in methods

The methods that are built in and resolved by the type of their receiver, one page each: `.len` ([`spec/14 §2`](https://una-lang.org/en/docs/spec/14-standard-library/#s2)), the methods of maps ([`spec/21 §2`](https://una-lang.org/en/docs/spec/21-maps/#s2)), the conversions ([`spec/18 §4`](https://una-lang.org/en/docs/spec/18-fixed-width-integers/#s4)) and the wrapping, saturating and bit operations of fixed-width integers ([`spec/18 §5`](https://una-lang.org/en/docs/spec/18-fixed-width-integers/#s5)). They have no declaration, so each signature line is written by una and tested against its checker.

Operators, comparisons, equality and interpolation are built in and not listed here ([`spec/14 §2`](https://una-lang.org/en/docs/spec/14-standard-library/#s2)).

## By area

Unstable\, not part of the specification\: see docs\/std\/README\.md\. Hand\-written\; crates\/una\-cli\/tests\/std\_listing\.rs checks it against the listing\.

The items described in full so far, with parameters, failures, cost where stated, and an example; 21 of this module's 52 are not yet.

### Text

- [`len`](https://una-lang.org/en/docs/std/builtin/len/): Built in on `Text` and `List` and, from edition 0.2 on, on `Map` (`spec/14 §2`, `spec/21 §2`).

### Numbers

- [`to_i8`](https://una-lang.org/en/docs/std/builtin/to_i8/): Converts `x` to that type.
- [`to_i16`](https://una-lang.org/en/docs/std/builtin/to_i16/): Converts `x` to that type.
- [`to_i32`](https://una-lang.org/en/docs/std/builtin/to_i32/): Converts `x` to that type.
- [`to_i64`](https://una-lang.org/en/docs/std/builtin/to_i64/): Converts `x` to that type.
- [`to_u8`](https://una-lang.org/en/docs/std/builtin/to_u8/): Converts `x` to that type.
- [`to_u16`](https://una-lang.org/en/docs/std/builtin/to_u16/): Converts `x` to that type.
- [`to_u32`](https://una-lang.org/en/docs/std/builtin/to_u32/): Converts `x` to that type.
- [`to_u64`](https://una-lang.org/en/docs/std/builtin/to_u64/): Converts `x` to that type.
- [`to_int`](https://una-lang.org/en/docs/std/builtin/to_int/): Converts `x` to `Int`, which every value of a fixed-width type fits, so it always succeeds (`spec/18 §4`).
- [`wrapping_add`](https://una-lang.org/en/docs/std/builtin/wrapping_add/): Total: the exact result reduced into the type's range modulo `2^w`, where `w` is its width (`spec/18 §5`).
- [`wrapping_sub`](https://una-lang.org/en/docs/std/builtin/wrapping_sub/): Total: the exact result reduced into the type's range modulo `2^w`, where `w` is its width (`spec/18 §5`).
- [`wrapping_mul`](https://una-lang.org/en/docs/std/builtin/wrapping_mul/): Total: the exact result reduced into the type's range modulo `2^w`, where `w` is its width (`spec/18 §5`).
- [`saturating_add`](https://una-lang.org/en/docs/std/builtin/saturating_add/): Total: the exact result clamped to the type's range (`spec/18 §5`).
- [`saturating_sub`](https://una-lang.org/en/docs/std/builtin/saturating_sub/): Total: the exact result clamped to the type's range (`spec/18 §5`).
- [`saturating_mul`](https://una-lang.org/en/docs/std/builtin/saturating_mul/): Total: the exact result clamped to the type's range (`spec/18 §5`).
- [`bit_and`](https://una-lang.org/en/docs/std/builtin/bit_and/): Total; on an unsigned type the result is at most `a` and at most `mask` (`spec/18 §5`).
- [`bit_or`](https://una-lang.org/en/docs/std/builtin/bit_or/): Total; on an unsigned type the result is at least `a` and at least `mask` (`spec/18 §5`).
- [`bit_xor`](https://una-lang.org/en/docs/std/builtin/bit_xor/): Total; its result is only known to be in the type's range (`spec/18 §5`).
- [`bit_not`](https://una-lang.org/en/docs/std/builtin/bit_not/): Total; its result is only known to be in the type's range (`spec/18 §5`).
- [`shift_right`](https://una-lang.org/en/docs/std/builtin/shift_right/): Requires `0 <= by` and `by` below the width; on an unsigned type the result is at most `a`.
- [`wrapping_shift_left`](https://una-lang.org/en/docs/std/builtin/wrapping_shift_left/): Requires `0 <= by` and `by` below the width: `a * 2^by` reduced into the type's range modulo `2^w`.

### Maps

- [`has`](https://una-lang.org/en/docs/std/builtin/has/): Whether `m` has `key`.
- [`get`](https://una-lang.org/en/docs/std/builtin/get/): `Some` exactly when `m.has(key: k)`.
- [`set`](https://una-lang.org/en/docs/std/builtin/set/): Updates `m` in place, written `edit m.set(...)`: afterwards `m.has(key: k)` and `m.get(key: k) == Some(v)`, and `m.len` grows by one when the key was not there (`spec/21 §2`).
- [`remove`](https://una-lang.org/en/docs/std/builtin/remove/): Updates `m` in place, written `edit m.remove(...)`: afterwards `not m.has(key: k)`, and `m.len` shrinks by one when the key was there (`spec/21 §2`).
- [`with`](https://una-lang.org/en/docs/std/builtin/with/): A map with the contract of `set`, for the result (`spec/21 §2`).
- [`without`](https://una-lang.org/en/docs/std/builtin/without/): A map with the contract of `remove`, for the result (`spec/21 §2`).
- [`keys`](https://una-lang.org/en/docs/std/builtin/keys/): The keys of `m`, in key order, as many as `m.len` (`spec/21 §2`).
- [`values`](https://una-lang.org/en/docs/std/builtin/values/): The values of `m`, in the order of their keys, as many as `m.len` (`spec/21 §2`).
- [`entries`](https://una-lang.org/en/docs/std/builtin/entries/): The entries of `m` as `Entry` values, in key order, as many as `m.len` (`spec/21 §2`).

## Methods

- [`len`](https://una-lang.org/en/docs/std/builtin/len/): Built in on `Text` and `List` and, from edition 0.2 on, on `Map` (`spec/14 §2`, `spec/21 §2`). (0.1 and later)
- [`has`](https://una-lang.org/en/docs/std/builtin/has/): Whether `m` has `key`. (0.2 and later)
- [`get`](https://una-lang.org/en/docs/std/builtin/get/): `Some` exactly when `m.has(key: k)`. (0.2 and later)
- [`set`](https://una-lang.org/en/docs/std/builtin/set/): Updates `m` in place, written `edit m.set(...)`: afterwards `m.has(key: k)` and `m.get(key: k) == Some(v)`, and `m.len` grows by one when the key was not there (`spec/21 §2`). (0.2 and later)
- [`remove`](https://una-lang.org/en/docs/std/builtin/remove/): Updates `m` in place, written `edit m.remove(...)`: afterwards `not m.has(key: k)`, and `m.len` shrinks by one when the key was there (`spec/21 §2`). (0.2 and later)
- [`with`](https://una-lang.org/en/docs/std/builtin/with/): A map with the contract of `set`, for the result (`spec/21 §2`). (0.2 and later)
- [`without`](https://una-lang.org/en/docs/std/builtin/without/): A map with the contract of `remove`, for the result (`spec/21 §2`). (0.2 and later)
- [`keys`](https://una-lang.org/en/docs/std/builtin/keys/): The keys of `m`, in key order, as many as `m.len` (`spec/21 §2`). (0.2 and later)
- [`values`](https://una-lang.org/en/docs/std/builtin/values/): The values of `m`, in the order of their keys, as many as `m.len` (`spec/21 §2`). (0.2 and later)
- [`entries`](https://una-lang.org/en/docs/std/builtin/entries/): The entries of `m` as `Entry` values, in key order, as many as `m.len` (`spec/21 §2`). (0.2 and later)
- [`update`](https://una-lang.org/en/docs/std/builtin/update/): Updates `m` in place, written `edit m.update(...)`: sets `key` to `change(v)`, where `v` is its value, or `initial` when `m` has no `key`. (0.5 preview)
- [`push`](https://una-lang.org/en/docs/std/builtin/push/): Updates the receiver in place, written `edit s.push(item: x)`: a `Stack` takes `item` on top and a `Queue` at its back, and its length grows by one, in O(1) amortized time (`spec/28 §5`). (0.5 preview)
- [`pop`](https://una-lang.org/en/docs/std/builtin/pop/): Updates the receiver in place, written `let x = edit s.pop()`: it removes the top of a `Stack` or the front of a `Queue` and gives it as `Some`, or gives `None` and leaves an empty one as it is, in O(1) amortized time (`spec/28 §5`). (0.5 preview)
- [`peek`](https://una-lang.org/en/docs/std/builtin/peek/): The top of a `Stack` or the front of a `Queue`, the item `pop` would remove, as `Some`, and `None` exactly when it is empty, in O(1) time (`spec/28 §5`). (0.5 preview)
- [`items`](https://una-lang.org/en/docs/std/builtin/items/): The items as a list: a `Stack` top first and a `Queue` front first, as many as its `len`, in O(n) time (`spec/28 §5`); a `Set`'s in ascending order, as many as its `len`, in O(n) time (`spec/28 §6`); a `HashSet`'s in the order its items were first added, in O(n) time (`spec/28 §7`); a `PriorityQueue`'s in the order of the pops, in O(n log n) comparisons (`spec/28 §8`); a `BitSet`'s members in ascending order, in O(size / 64 + len) time (`spec/28 §9`). (0.5 preview)
- [`push_front`](https://una-lang.org/en/docs/std/builtin/push_front/): Updates a `Queue` in place, written `edit q.push_front(item: x)`: `item` goes to the front, so `peek` gives it, in O(1) amortized time (`spec/28 §5`). (0.5 preview)
- [`pop_back`](https://una-lang.org/en/docs/std/builtin/pop_back/): Updates a `Queue` in place, written `let x = edit q.pop_back()`: it removes the back and gives it as `Some`, or gives `None` when the queue is empty, in O(1) amortized time (`spec/28 §5`). (0.5 preview)
- [`peek_back`](https://una-lang.org/en/docs/std/builtin/peek_back/): The back of a `Queue`, the item `pop_back` would remove, as `Some`, and `None` exactly when it is empty, in O(1) time (`spec/28 §5`). (0.5 preview)
- [`add`](https://una-lang.org/en/docs/std/builtin/add/): Updates `s` in place, written `edit s.add(...)`: afterwards `s.has(item: x)`, and `s.len` grows by one when the item was not there. (0.5 preview)
- [`first`](https://una-lang.org/en/docs/std/builtin/first/): The least item of `s`, or `None` when it is empty. (0.5 preview)
- [`last`](https://una-lang.org/en/docs/std/builtin/last/): The greatest item of `s`, or `None` when it is empty. (0.5 preview)
- [`between`](https://una-lang.org/en/docs/std/builtin/between/): The items of `s` from `low` to `high`, both included, in ascending order; none when `low` is above `high`. (0.5 preview)
- [`union`](https://una-lang.org/en/docs/std/builtin/union/): The items of `s` and those of `other`. (0.5 preview)
- [`intersection`](https://una-lang.org/en/docs/std/builtin/intersection/): The items of `s` that `other` holds. (0.5 preview)
- [`difference`](https://una-lang.org/en/docs/std/builtin/difference/): The items of `s` that `other` does not hold. (0.5 preview)
- [`is_subset`](https://una-lang.org/en/docs/std/builtin/is_subset/): Whether `of` holds every item of `s`. (0.5 preview)
- [`same_entries`](https://una-lang.org/en/docs/std/builtin/same_entries/): Whether `m` and `as` have the same keys, each with an equal value, whatever the order they were added in; `V` must satisfy `Eq`. (0.5 preview)
- [`same_items`](https://una-lang.org/en/docs/std/builtin/same_items/): Whether `s` and `as` hold the same items, whatever the order they were added in. (0.5 preview)
- [`pop_ranked`](https://una-lang.org/en/docs/std/builtin/pop_ranked/): Updates a `PriorityQueue` in place, written `let r = edit q.pop_ranked()`: as `pop`, with the priority, as `Some` of a `Ranked`, in O(log n) comparisons, amortized (`spec/28 §8`). (0.5 preview)
- [`peek_priority`](https://una-lang.org/en/docs/std/builtin/peek_priority/): The priority of the item that `pop` would give from a `PriorityQueue`, as `Some`, and `None` exactly when it is empty, in O(1) time (`spec/28 §8`). (0.5 preview)
- [`size`](https://una-lang.org/en/docs/std/builtin/size/): The number of bits of a `BitSet`, fixed when `empty_bit_set` makes it: its members are integers from 0 to `size - 1`. (0.5 preview)
- [`to_i8`](https://una-lang.org/en/docs/std/builtin/to_i8/): Converts `x` to that type. (0.2 and later)
- [`to_i16`](https://una-lang.org/en/docs/std/builtin/to_i16/): Converts `x` to that type. (0.2 and later)
- [`to_i32`](https://una-lang.org/en/docs/std/builtin/to_i32/): Converts `x` to that type. (0.2 and later)
- [`to_i64`](https://una-lang.org/en/docs/std/builtin/to_i64/): Converts `x` to that type. (0.2 and later)
- [`to_u8`](https://una-lang.org/en/docs/std/builtin/to_u8/): Converts `x` to that type. (0.2 and later)
- [`to_u16`](https://una-lang.org/en/docs/std/builtin/to_u16/): Converts `x` to that type. (0.2 and later)
- [`to_u32`](https://una-lang.org/en/docs/std/builtin/to_u32/): Converts `x` to that type. (0.2 and later)
- [`to_u64`](https://una-lang.org/en/docs/std/builtin/to_u64/): Converts `x` to that type. (0.2 and later)
- [`to_int`](https://una-lang.org/en/docs/std/builtin/to_int/): Converts `x` to `Int`, which every value of a fixed-width type fits, so it always succeeds (`spec/18 §4`). (0.2 and later)
- [`wrapping_add`](https://una-lang.org/en/docs/std/builtin/wrapping_add/): Total: the exact result reduced into the type's range modulo `2^w`, where `w` is its width (`spec/18 §5`). (0.2 and later)
- [`wrapping_sub`](https://una-lang.org/en/docs/std/builtin/wrapping_sub/): Total: the exact result reduced into the type's range modulo `2^w`, where `w` is its width (`spec/18 §5`). (0.2 and later)
- [`wrapping_mul`](https://una-lang.org/en/docs/std/builtin/wrapping_mul/): Total: the exact result reduced into the type's range modulo `2^w`, where `w` is its width (`spec/18 §5`). (0.2 and later)
- [`saturating_add`](https://una-lang.org/en/docs/std/builtin/saturating_add/): Total: the exact result clamped to the type's range (`spec/18 §5`). (0.2 and later)
- [`saturating_sub`](https://una-lang.org/en/docs/std/builtin/saturating_sub/): Total: the exact result clamped to the type's range (`spec/18 §5`). (0.2 and later)
- [`saturating_mul`](https://una-lang.org/en/docs/std/builtin/saturating_mul/): Total: the exact result clamped to the type's range (`spec/18 §5`). (0.2 and later)
- [`bit_and`](https://una-lang.org/en/docs/std/builtin/bit_and/): Total; on an unsigned type the result is at most `a` and at most `mask` (`spec/18 §5`). (0.2 and later)
- [`bit_or`](https://una-lang.org/en/docs/std/builtin/bit_or/): Total; on an unsigned type the result is at least `a` and at least `mask` (`spec/18 §5`). (0.2 and later)
- [`bit_xor`](https://una-lang.org/en/docs/std/builtin/bit_xor/): Total; its result is only known to be in the type's range (`spec/18 §5`). (0.2 and later)
- [`bit_not`](https://una-lang.org/en/docs/std/builtin/bit_not/): Total; its result is only known to be in the type's range (`spec/18 §5`). (0.2 and later)
- [`shift_right`](https://una-lang.org/en/docs/std/builtin/shift_right/): Requires `0 <= by` and `by` below the width; on an unsigned type the result is at most `a`. (0.2 and later)
- [`wrapping_shift_left`](https://una-lang.org/en/docs/std/builtin/wrapping_shift_left/): Requires `0 <= by` and `by` below the width: `a * 2^by` reduced into the type's range modulo `2^w`. (0.2 and later)

Generated from una v0.4.0 ([`docs/std/builtins.json`](https://github.com/una-lang/una/blob/5fec93d88932b333feec25e589355a2cb34c37b5/docs/std/builtins.json), which is not part of the specification): built-in methods have no declaration, so una writes these signature lines and tests each against its checker. The specification governs: [`spec/14 §2`](https://una-lang.org/en/docs/spec/14-standard-library/#s2).
