Alpha.16 · standard library

Bytes

Construct empty bytes and take bounded slices. Byte values are distinct from text.

These pages describe alpha.16. Host I/O requires the native toolchain; browser capabilities are limited. Browse the stdlib guides.

All standard library modules

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.

Keep exploring

Explore Panackelty.