Home / Docs / Standard library
Built-in methods
The methods that are built in and resolved by the type of their receiver, one page each: .len (spec/14 §2), the methods of maps (spec/21 §2), the conversions (spec/18 §4) and the wrapping, saturating and bit operations of fixed-width integers (spec/18 §5). 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).
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: Built in onTextandListand, from edition 0.2 on, onMap(spec/14 §2, spec/21 §2).
Numbers
to_i8: Convertsxto that type.to_i16: Convertsxto that type.to_i32: Convertsxto that type.to_i64: Convertsxto that type.to_u8: Convertsxto that type.to_u16: Convertsxto that type.to_u32: Convertsxto that type.to_u64: Convertsxto that type.to_int: ConvertsxtoInt, which every value of a fixed-width type fits, so it always succeeds (spec/18 §4).wrapping_add: Total: the exact result reduced into the type's range modulo2^w, wherewis its width (spec/18 §5).wrapping_sub: Total: the exact result reduced into the type's range modulo2^w, wherewis its width (spec/18 §5).wrapping_mul: Total: the exact result reduced into the type's range modulo2^w, wherewis its width (spec/18 §5).saturating_add: Total: the exact result clamped to the type's range (spec/18 §5).saturating_sub: Total: the exact result clamped to the type's range (spec/18 §5).saturating_mul: Total: the exact result clamped to the type's range (spec/18 §5).bit_and: Total; on an unsigned type the result is at mostaand at mostmask(spec/18 §5).bit_or: Total; on an unsigned type the result is at leastaand at leastmask(spec/18 §5).bit_xor: Total; its result is only known to be in the type's range (spec/18 §5).bit_not: Total; its result is only known to be in the type's range (spec/18 §5).shift_right: Requires0 <= byandbybelow the width; on an unsigned type the result is at mosta.wrapping_shift_left: Requires0 <= byandbybelow the width:a * 2^byreduced into the type's range modulo2^w.
Maps
has: Whethermhaskey.get:Someexactly whenm.has(key: k).set: Updatesmin place, writtenedit m.set(...): afterwardsm.has(key: k)andm.get(key: k) == Some(v), andm.lengrows by one when the key was not there (spec/21 §2).remove: Updatesmin place, writtenedit m.remove(...): afterwardsnot m.has(key: k), andm.lenshrinks by one when the key was there (spec/21 §2).with: A map with the contract ofset, for the result (spec/21 §2).without: A map with the contract ofremove, for the result (spec/21 §2).keys: The keys ofm, in key order, as many asm.len(spec/21 §2).values: The values ofm, in the order of their keys, as many asm.len(spec/21 §2).entries: The entries ofmasEntryvalues, in key order, as many asm.len(spec/21 §2).
Methods
len: Built in onTextandListand, from edition 0.2 on, onMap(spec/14 §2, spec/21 §2). (0.1 and later)has: Whethermhaskey. (0.2 and later)get:Someexactly whenm.has(key: k). (0.2 and later)set: Updatesmin place, writtenedit m.set(...): afterwardsm.has(key: k)andm.get(key: k) == Some(v), andm.lengrows by one when the key was not there (spec/21 §2). (0.2 and later)remove: Updatesmin place, writtenedit m.remove(...): afterwardsnot m.has(key: k), andm.lenshrinks by one when the key was there (spec/21 §2). (0.2 and later)with: A map with the contract ofset, for the result (spec/21 §2). (0.2 and later)without: A map with the contract ofremove, for the result (spec/21 §2). (0.2 and later)keys: The keys ofm, in key order, as many asm.len(spec/21 §2). (0.2 and later)values: The values ofm, in the order of their keys, as many asm.len(spec/21 §2). (0.2 and later)entries: The entries ofmasEntryvalues, in key order, as many asm.len(spec/21 §2). (0.2 and later)update: Updatesmin place, writtenedit m.update(...): setskeytochange(v), wherevis its value, orinitialwhenmhas nokey. (0.5 preview)push: Updates the receiver in place, writtenedit s.push(item: x): aStacktakesitemon top and aQueueat its back, and its length grows by one, in O(1) amortized time (spec/28 §5). (0.5 preview)pop: Updates the receiver in place, writtenlet x = edit s.pop(): it removes the top of aStackor the front of aQueueand gives it asSome, or givesNoneand leaves an empty one as it is, in O(1) amortized time (spec/28 §5). (0.5 preview)peek: The top of aStackor the front of aQueue, the itempopwould remove, asSome, andNoneexactly when it is empty, in O(1) time (spec/28 §5). (0.5 preview)items: The items as a list: aStacktop first and aQueuefront first, as many as itslen, in O(n) time (spec/28 §5); aSet's in ascending order, as many as itslen, in O(n) time (spec/28 §6); aHashSet's in the order its items were first added, in O(n) time (spec/28 §7); aPriorityQueue's in the order of the pops, in O(n log n) comparisons (spec/28 §8); aBitSet's members in ascending order, in O(size / 64 + len) time (spec/28 §9). (0.5 preview)push_front: Updates aQueuein place, writtenedit q.push_front(item: x):itemgoes to the front, sopeekgives it, in O(1) amortized time (spec/28 §5). (0.5 preview)pop_back: Updates aQueuein place, writtenlet x = edit q.pop_back(): it removes the back and gives it asSome, or givesNonewhen the queue is empty, in O(1) amortized time (spec/28 §5). (0.5 preview)peek_back: The back of aQueue, the itempop_backwould remove, asSome, andNoneexactly when it is empty, in O(1) time (spec/28 §5). (0.5 preview)add: Updatessin place, writtenedit s.add(...): afterwardss.has(item: x), ands.lengrows by one when the item was not there. (0.5 preview)first: The least item ofs, orNonewhen it is empty. (0.5 preview)last: The greatest item ofs, orNonewhen it is empty. (0.5 preview)between: The items ofsfromlowtohigh, both included, in ascending order; none whenlowis abovehigh. (0.5 preview)union: The items ofsand those ofother. (0.5 preview)intersection: The items ofsthatotherholds. (0.5 preview)difference: The items ofsthatotherdoes not hold. (0.5 preview)is_subset: Whetherofholds every item ofs. (0.5 preview)same_entries: Whethermandashave the same keys, each with an equal value, whatever the order they were added in;Vmust satisfyEq. (0.5 preview)same_items: Whethersandashold the same items, whatever the order they were added in. (0.5 preview)pop_ranked: Updates aPriorityQueuein place, writtenlet r = edit q.pop_ranked(): aspop, with the priority, asSomeof aRanked, in O(log n) comparisons, amortized (spec/28 §8). (0.5 preview)peek_priority: The priority of the item thatpopwould give from aPriorityQueue, asSome, andNoneexactly when it is empty, in O(1) time (spec/28 §8). (0.5 preview)size: The number of bits of aBitSet, fixed whenempty_bit_setmakes it: its members are integers from 0 tosize - 1. (0.5 preview)to_i8: Convertsxto that type. (0.2 and later)to_i16: Convertsxto that type. (0.2 and later)to_i32: Convertsxto that type. (0.2 and later)to_i64: Convertsxto that type. (0.2 and later)to_u8: Convertsxto that type. (0.2 and later)to_u16: Convertsxto that type. (0.2 and later)to_u32: Convertsxto that type. (0.2 and later)to_u64: Convertsxto that type. (0.2 and later)to_int: ConvertsxtoInt, which every value of a fixed-width type fits, so it always succeeds (spec/18 §4). (0.2 and later)wrapping_add: Total: the exact result reduced into the type's range modulo2^w, wherewis its width (spec/18 §5). (0.2 and later)wrapping_sub: Total: the exact result reduced into the type's range modulo2^w, wherewis its width (spec/18 §5). (0.2 and later)wrapping_mul: Total: the exact result reduced into the type's range modulo2^w, wherewis its width (spec/18 §5). (0.2 and later)saturating_add: Total: the exact result clamped to the type's range (spec/18 §5). (0.2 and later)saturating_sub: Total: the exact result clamped to the type's range (spec/18 §5). (0.2 and later)saturating_mul: Total: the exact result clamped to the type's range (spec/18 §5). (0.2 and later)bit_and: Total; on an unsigned type the result is at mostaand at mostmask(spec/18 §5). (0.2 and later)bit_or: Total; on an unsigned type the result is at leastaand at leastmask(spec/18 §5). (0.2 and later)bit_xor: Total; its result is only known to be in the type's range (spec/18 §5). (0.2 and later)bit_not: Total; its result is only known to be in the type's range (spec/18 §5). (0.2 and later)shift_right: Requires0 <= byandbybelow the width; on an unsigned type the result is at mosta. (0.2 and later)wrapping_shift_left: Requires0 <= byandbybelow the width:a * 2^byreduced into the type's range modulo2^w. (0.2 and later)
Generated from una v0.4.0 (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.