Home / Docs / Standard library
Prelude
The items of the prelude, which every module has in scope, one page each. Some signatures differ between editions; an item's page shows each.
Operators, comparisons, equality and interpolation are built in and not listed here (spec/14 §2). The built-in methods, .len and those of maps and of fixed-width integers, are on Built-in methods.
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; 31 of this module's 81 are not yet.
Text
is_digits: Whether every character oftis an ASCII digit, so it holds of the empty text (spec/14 §1).starts_with: Whethertstarts withprefix, comparing Unicode scalar values (spec/14 §1).trim:twithout the Unicode whitespace at both ends (spec/14 §1).to_int:Someof the integer thattwrites whentis an optional-followed by one or more ASCII digits, leading zeros allowed, andNonefor any other text: the empty text,"-", a leading+, whitespace or digits outside ASCII.ParseError: Whyparse_intfails (spec/22 §4).split: The parts oftbetween the non-overlapping occurrences ofon, left to right (spec/22 §2).join: The parts joined, withseparatorbetween each two (spec/22 §2).ends_with: Whethertends withsuffix(spec/22 §2).contains_text: Whetherpartoccurs int(spec/22 §2).find: The position of the first occurrence oftextint,Some(0)for an emptytext; it isSomeexactly whencontains_text(t, part: text)(spec/22 §2 rule 2).replace:twith every non-overlapping occurrence ofpatternreplaced byby, left to right (spec/22 §2).slice: The scalar values oftfrom positionstartup to, not including,end(spec/22 §2).to_upper:twith the ASCII lettersatozin upper case (spec/22 §3).to_lower:twith the ASCII lettersAtoZin lower case (spec/22 §3).chars: One text of length 1 per scalar value oft, in order (spec/22 §2).parse_int: The integer thattwrites, an optional-and one or more ASCII digits (spec/22 §4).trim_start:twithout Unicode white space at its start (spec/22 §2).trim_end:twithout Unicode white space at its end (spec/22 §2).bytes: The UTF-8 encoding oft(spec/22 §2).
Numbers
Nat: AnIntthat is at least zero: anIntflows intoNatwhere the bound is proved (spec/14 §1, spec/03 §2).abs: The absolute value ofx(spec/14 §1).min: The smaller ofaandb; in edition 0.2 and later, of any type withOrd(spec/14 §1, spec/20 §6).max: The larger ofaandb; in edition 0.2 and later, of any type withOrd(spec/14 §1, spec/20 §6).
Lists
is_empty: Whetherxshas no elements (spec/14 §1).first:Someof the element at position 0, andNoneexactly whenxsis empty (spec/14 §1).at:Someof the element at positionindex, counted from 0, andNoneexactly whenindexis below0or at leastxs.len; it never fails (spec/14 §1).append:xswithitemadded after its last element (spec/14 §1).contains: Compares structurally; in edition 0.2 and later, over any type withEq(spec/14 §1, spec/20 §6).map: The list ofeach(x)for each elementxofxs, in the order ofxs;eachis called from the first element to the last, at most once per element.filter: The elementsxofxsfor whichkeep(x)istrue, in the order ofxs;keepis called from the first element to the last, at most once per element.first_where:Someof the first elementxofxsfor whichkeep(x)istrue, andNonewhen there is none;keepis called from the first element up to that one, at most once per element, and not after it.fold: Starts frominitialand, for each elementxofxsfrom the first to the last, replaces the accumulatoraccbystep(acc, x), callingstepat most once per element; the result is the last accumulator,initialwhenxsis empty.sum: The exact sum of the elements as anInt,0whenxsis empty;Inthas no bound, so it never overflows.set: Replaces the element atindexofxswithitem(spec/17 §8).sort: The elements ofxsin ascending order, equal ones in their order inxs(spec/20 §6).
Options and results
Option: EitherSome(value), which holds one value ofT, orNone, which holds none (spec/14 §1).Result: EitherOk(value), which holds the success value ofT, orErr(failure), which holds the failure ofE(spec/14 §1).is_some: WhetheroisSome(spec/14 §1).or_else: The valuevwhenoisSome(v), anddefaultwhenoisNone;defaultis an argument like any other, evaluated before the call (spec/14 §1).is_ok: WhetherrisOk(spec/14 §1).
Maps
Entry: An entry of a map, asentries()lists them (spec/21 §1 rule 4).empty_map: The map with no entries, of the type its context expects (spec/21 §2).
JSON
is_json_number: Whethertis one JSON number of RFC 8259 §6 (spec/23 §1).JsonNumber: The text of a JSON number with a fraction or an exponent, whichDecimalholds (spec/23 §1).Json: A JSON value (spec/23 §1).JsonError: Why a text is not one JSON value, at the first error in reading order (spec/23 §3).parse_json: The one JSON value oft(spec/23 §3).to_json: The canonical JSON text ofj(spec/23 §4).quote_json:tas a JSON string literal (spec/23 §4 rule 2).
Keys
KeyError: WhyKeys.hmacfails:UnknownKey, a key name that the key file of the grant does not hold (spec/14 §3, spec/13 §5).
Types
Nat: AnIntthat is at least zero: anIntflows intoNatwhere the bound is proved (spec/14 §1, spec/03 §2). (0.1 and later)Option: EitherSome(value), which holds one value ofT, orNone, which holds none (spec/14 §1). (0.1 and later)Result: EitherOk(value), which holds the success value ofT, orErr(failure), which holds the failure ofE(spec/14 §1). (0.1 and later)FileError: Why an operation ofFilesfails (spec/14 §3). (0.1 and later)KeyError: WhyKeys.hmacfails:UnknownKey, a key name that the key file of the grant does not hold (spec/14 §3, spec/13 §5). (0.1 and later)Entry: An entry of a map, asentries()lists them (spec/21 §1 rule 4). (0.2 and later)JsonNumber: The text of a JSON number with a fraction or an exponent, whichDecimalholds (spec/23 §1). (0.2 and later)Json: A JSON value (spec/23 §1). (0.2 and later)JsonError: Why a text is not one JSON value, at the first error in reading order (spec/23 §3). (0.2 and later)ParseError: Whyparse_intfails (spec/22 §4). (0.2 and later)Header: A header of an HTTP request or response (spec/24 §1). (0.2 and later)Response: An HTTP response, whatever its status (spec/24 §1 rule 3). (0.2 and later)HttpError: Why an HTTP request got no response it may return (spec/24 §1 rule 3). (0.2 and later)Rounding: How a decimal operation rounds an exact value to the units of its result's scale (spec/29 §16): on the magnitude, then the sign. (0.5 preview)Finite64: AnF64that is neither NaN nor an infinity (spec/29 §18, ADR 0120 rule 11). (0.5 preview)Finite32: AnF32that is neither NaN nor an infinity (spec/29 §18, ADR 0120 rule 11). (0.5 preview)
Capabilities
Console: Writes lines to standard output:printwrites the line and a newline. (0.1 and later)Clock: Reads the time:nowgives the milliseconds since the Unix epoch. (0.1 and later)Env: Reads a process environment variable, asinternaltext. (0.1 and later)Files: Reads and writes files, with paths relative to the prefix the grant fixes; each operation can fail withFileError(spec/14 §3). (0.1 and later)Keys: Computes an HMAC-SHA-256 with a named key of the grant's key file, asinternalHashed. (0.1 and later)Http: HTTP/1.1 to the origins thathttp:grants allow (spec/24 §1). (0.2 and later)
Functions
abs: The absolute value ofx(spec/14 §1). (0.1 and later)min: The smaller ofaandb; in edition 0.2 and later, of any type withOrd(spec/14 §1, spec/20 §6). (0.1 and later)max: The larger ofaandb; in edition 0.2 and later, of any type withOrd(spec/14 §1, spec/20 §6). (0.1 and later)is_digits: Whether every character oftis an ASCII digit, so it holds of the empty text (spec/14 §1). (0.1 and later)starts_with: Whethertstarts withprefix, comparing Unicode scalar values (spec/14 §1). (0.1 and later)trim:twithout the Unicode whitespace at both ends (spec/14 §1). (0.1 and later)to_int:Someof the integer thattwrites whentis an optional-followed by one or more ASCII digits, leading zeros allowed, andNonefor any other text: the empty text,"-", a leading+, whitespace or digits outside ASCII. (0.1 and later)is_empty: Whetherxshas no elements (spec/14 §1). (0.1 and later)first:Someof the element at position 0, andNoneexactly whenxsis empty (spec/14 §1). (0.1 and later)at:Someof the element at positionindex, counted from 0, andNoneexactly whenindexis below0or at leastxs.len; it never fails (spec/14 §1). (0.1 and later)append:xswithitemadded after its last element (spec/14 §1). (0.1 and later)contains: Compares structurally; in edition 0.2 and later, over any type withEq(spec/14 §1, spec/20 §6). (0.1 and later)map: The list ofeach(x)for each elementxofxs, in the order ofxs;eachis called from the first element to the last, at most once per element. (0.1 and later)filter: The elementsxofxsfor whichkeep(x)istrue, in the order ofxs;keepis called from the first element to the last, at most once per element. (0.1 and later)first_where:Someof the first elementxofxsfor whichkeep(x)istrue, andNonewhen there is none;keepis called from the first element up to that one, at most once per element, and not after it. (0.1 and later)fold: Starts frominitialand, for each elementxofxsfrom the first to the last, replaces the accumulatoraccbystep(acc, x), callingstepat most once per element; the result is the last accumulator,initialwhenxsis empty. (0.1 and later)sum: The exact sum of the elements as anInt,0whenxsis empty;Inthas no bound, so it never overflows. (0.1 and later)is_some: WhetheroisSome(spec/14 §1). (0.1 and later)or_else: The valuevwhenoisSome(v), anddefaultwhenoisNone;defaultis an argument like any other, evaluated before the call (spec/14 §1). (0.1 and later)is_ok: WhetherrisOk(spec/14 §1). (0.1 and later)set: Replaces the element atindexofxswithitem(spec/17 §8). (0.2 and later)sort: The elements ofxsin ascending order, equal ones in their order inxs(spec/20 §6). (0.2 and later)empty_map: The map with no entries, of the type its context expects (spec/21 §2). (0.2 and later)parse_json: The one JSON value oft(spec/23 §3). (0.2 and later)to_json: The canonical JSON text ofj(spec/23 §4). (0.2 and later)quote_json:tas a JSON string literal (spec/23 §4 rule 2). (0.2 and later)split: The parts oftbetween the non-overlapping occurrences ofon, left to right (spec/22 §2). (0.2 and later)join: The parts joined, withseparatorbetween each two (spec/22 §2). (0.2 and later)ends_with: Whethertends withsuffix(spec/22 §2). (0.2 and later)contains_text: Whetherpartoccurs int(spec/22 §2). (0.2 and later)find: The position of the first occurrence oftextint,Some(0)for an emptytext; it isSomeexactly whencontains_text(t, part: text)(spec/22 §2 rule 2). (0.2 and later)replace:twith every non-overlapping occurrence ofpatternreplaced byby, left to right (spec/22 §2). (0.2 and later)slice: The scalar values oftfrom positionstartup to, not including,end(spec/22 §2). (0.2 and later)to_upper:twith the ASCII lettersatozin upper case (spec/22 §3). (0.2 and later)to_lower:twith the ASCII lettersAtoZin lower case (spec/22 §3). (0.2 and later)chars: One text of length 1 per scalar value oft, in order (spec/22 §2). (0.2 and later)parse_int: The integer thattwrites, an optional-and one or more ASCII digits (spec/22 §4). (0.2 and later)trim_start:twithout Unicode white space at its start (spec/22 §2). (0.2 and later)trim_end:twithout Unicode white space at its end (spec/22 §2). (0.2 and later)bytes: The UTF-8 encoding oft(spec/22 §2). (0.2 and later)nan: The canonical NaN,0x7FF8000000000000: the one NaN ofF64(spec/29 §3). (0.3, 0.4, 0.5 preview)infinity: The positive infinity ofF64;-infinity()is the negative one (spec/29 §3). (0.3, 0.4, 0.5 preview)f64_from_bits: TheF64with the bitsbits; any NaN gives the canonical NaN (spec/29 §3). (0.3, 0.4, 0.5 preview)parse_f64: TheF64thattwrites, a JSON number,nan,infor-inf, correctly rounded, or why it writes none (spec/29 §7). (0.3, 0.4, 0.5 preview)as_f64: TheF64nearest a JSON number,Nonefor any otherJson(spec/29 §10). (0.3, 0.4, 0.5 preview)json_number:xas a JSON number,Nonefor NaN and the infinities (spec/29 §10). (0.3, 0.4, 0.5 preview)parse_decimal: TheDecimal[s]thattwrites at the scalesof the literalscale, or why it writes none (spec/29 §16). (0.5 preview)as_decimal: TheDecimal[s]of a JSON number at the scalesof the literalscale,Nonewhen it has no exact value there, and for any otherJson(spec/29 §16). (0.5 preview)json_decimal: ADecimal[s]as a JSON number:Numberat scale 0,Decimalotherwise (spec/29 §16). (0.5 preview)array: An array of the elements ofxs, in order (spec/29 §17, ADR 0120 rule 32). (0.5 preview)array_filled: An array oflengthelements, eachvalue(spec/29 §17). (0.5 preview)matrix: A matrix ofrowsrows andcolumnscolumns, the elements ofelementsin row-major order (spec/29 §17). (0.5 preview)matrix_filled: A matrix ofrowsrows andcolumnscolumns, each elementvalue(spec/29 §17). (0.5 preview)matrix_diagonal: The square matrix withvalueson its diagonal and+0of the element type elsewhere (spec/29 §17). (0.5 preview)tensor: A tensor of the lengths inshape, a list literal of 1 to 8 of them, with the elements ofelementsin row-major order (spec/29 §17). (0.5 preview)tensor_filled: A tensor of the lengths inshape, a list literal of 1 to 8 of them, each elementvalue(spec/29 §17):requiresevery length>= 0,ensuresthe rank and the lengths, as fortensor. (0.5 preview)f32_from_bits: TheF32with the bitsbits; any NaN gives the canonical NaN0x7FC00000(spec/29 §18, ADR 0120 rule 5). (0.5 preview)parse_f32: TheF32thattwrites, a JSON number,nan,infor-inf, rounded once to the nearestF32, or why it writes none (spec/29 §18, ADR 0120 rule 5). (0.5 preview)
Predicates
is_json_number: Whethertis one JSON number of RFC 8259 §6 (spec/23 §1). (0.2 and later)
Generated from the standard modules of una v0.4.0 (docs/std/listing.json, which is not part of the specification). The specification governs: spec/14 §1.