Home / Docs / Standard library / Prelude
bytes
Release v0.4.0Edition 0.2 and later
A function of the prelude, in scope in every module. Edition 0.2 and later.
una
pub bytes(t: Text) -> List[U8]
ensures result.len >= t.lenThe UTF-8 encoding of t (spec/22 §2).
Parameters
t: the text
Returns
List[U8]: the UTF-8 encoding of t; at least as many bytes as t has scalar values.
See also
Cost
Time O(b) (ADR 0070), where:
b: the length oftin UTF-8 bytes
Example
src/shop.una
module shop
--- How many bytes a product name takes in UTF-8.
pub main() -> Unit
uses @console: Console[print]
=
let plain = "Lamp".bytes().len
@console.print("Lamp: {plain} bytes")
let accented = "Café".bytes().len
@console.print("Café: {accented} bytes")una run . prints:
Output
Lamp: 4 bytes
Café: 5 bytesSpecification
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.