Types
Growable byte buffer / string builder from std.bytes.
An opaque handle: only std.bytes can produce one, and its contents are not reachable from moon source.
use std.bytes
use std.bytes.Bytes
fn main() {
let out: Bytes = bytes.with_capacity(16)
out.append_string("moon ")
out.append_int(42)
out.push(33)
println(out.to_string())
println(out.len())
println(out.slice(0, 4).to_array())
out.set(0, 109)
out.clear()
}_handle: NativeHandle | The native buffer. |
|---|
Functions
An empty growable byte buffer (also the string builder).
An empty buffer with at least n bytes reserved.
A read-only buffer borrowing the string's bytes. O(1), no copy; the first mutation detaches.
A buffer from an array of byte values (each 0..=255).
Appends one byte (0..=255). Amortized O(1).
Appends another buffer's contents.
Appends a string's bytes. Amortized O(1) per byte.
Appends a string with JSON's escapes applied (quote, backslash, and every control byte; \u00xx for the ones without a short form), copying unescaped runs in bulk. One pass, no intermediate string, and no surrounding quotes — the caller writes those.
Appends a float in the same shortest round-trip spelling to_string gives it, with no intermediate string. Returns 0 when what it wrote has no . or exponent (an integral value), 1 when it has, and 2 for a non-finite value — which has no such spelling, so nothing is written and the caller decides what its format says instead.
Appends an integer's decimal spelling to the builder — no intermediate string, and no digit loop in the caller.
Index of the first byte at or after from that is not an ASCII digit (the string's length when it runs out). O(n) over the digits, allocates nothing.
Index of the first occurrence of byte at or after from, or the string's length when there is none. Allocates nothing.
The byte at index i; errors when out of bounds.
Stores a byte (0..=255) at index i; errors when out of bounds.
A shared view of the range [lo, hi); O(1), no copy. Mutating either side detaches first, so contents never alias observably.
The contents as a string, byte-faithful (the builder's finish). O(1): the backing is frozen and borrowed, not copied.
Byte length of a string view. O(1), allocates nothing.
The byte at index i of a string view; errors when out of bounds. O(1), allocates nothing.
The byte range [lo, hi) as a string sharing the source backing. O(1), allocates nothing; errors when out of range.
The buffer's byte range [lo, hi) as a string sharing its backing — the ranged form of to_string. O(1), allocates nothing.
The contents as an array of byte values.
Resets length to zero, keeping capacity.