Construct empty bytes and take bounded slices. Byte values are distinct from text.
Import
import stdlib/bytes as bytes
empty()
pure empty(): Bytes
Parameters
None.
Returns: Bytes, an empty byte sequence.
Pure. Equivalent to constructing bytes().
slice()
pure slice(data: Bytes, start: Nat, end: Nat): Bytes
Parameters
data: Bytes— source bytes.start: Nat— start offset, inclusive.end: Nat— end offset, exclusive.
Returns: Bytes, the selected slice.
Pure compatibility function. Uses the bounds and failure contract of Bytes.slice.
Value methods
Bytes.len()
pure len(): Nat
Parameters
None.
Returns: Nat, the number of bytes.
The compatibility method length() returns the same count.
Bytes.slice()
pure slice(start: Nat, end: Nat): Bytes
Parameters
start: Nat: start offset, inclusive.end: Nat: end offset, exclusive.
Returns: Bytes, the selected half-open slice of this value.
Errors: Bounds must satisfy start <= end <= self.len(). Invalid bounds trap; this operation does not return a Result.
UTF-8 decoding is a separate checked operation: utf8.decode.
Implementation: view source on GitHub.