Expand description
The Text scalar descriptor (§4.3, ADR-013).
Text is an immutable UTF-8 payload referenced through a GcRef (§4.3).
§4.3 allows two representations:
- An owned UTF-8 payload (
Box<str>). - A source slice carrying
(owner: GcRef, start, length)(§7.10) — a zero-copy view into anotherText(typically the process-input buffer).
Both are produced: the input parser allocates source slices pointing into
the immutable stdin buffer, and string literals are owned. The descriptor
callbacks handle both variants through text_bytes, which follows slice
owners — sound because the collector is non-moving (ADR-011) and owners are
kept alive by GC reachability. Every walk of an owner chain in this module
is iterative, because nothing bounds its depth
(reading_a_deep_slice_chain_does_not_recurse).
Owned payloads own a Rust allocation (Box<str>), so TEXT’s drop_value
releases it on sweep (§12.5). Slice payloads carry only a GcRef (traced, not
owned) plus offsets — no Rust resources to drop.
An owned payload additionally carries a lazily computed scalar count
(ADR-115), which is what makes t.len() and t[i] O(1) on the texts a
program actually indexes. The count is the whole mechanism: count == bytes.len() is exactly “every scalar in this text is one byte”, so it is
both the length answer and the byte-indexing licence, and a slice inherits
the licence from its owner because a view of one-byte scalars is one-byte
scalars. See text_char_count and text_ascii_bytes.
Structs§
- Owned
Text - An owned UTF-8 payload and the number of Unicode scalars in it, computed on first demand (ADR-115).
- Source
Slice - A validated zero-copy view of
owner’s bytes over[start, start + len).
Enums§
- Text
Payload - The
Textpayload: either an owned UTF-8 string or a zero-copy slice into anotherText(the input buffer) (§4.3, §7.10, ADR-013).
Statics§
- TEXT
- Descriptor for the
Textscalar (§4.3). Handles both owned and source-slice payloads (ADR-013). A single descriptor serves allTextvalues.
Functions§
- text_
ascii_ ⚠bytes - The bytes of
payloadwhen a byte index into them is a character index — that is, when every scalar in the text is one byte wide — andNoneotherwise. - text_
bytes ⚠ - Read the UTF-8 bytes of a
TextPayload, following slice owners. - text_
char_ ⚠count - The number of Unicode scalars in
payload—t.len()’s answer (§4.3, ADR-086) — in O(1) once the text or its owner has been counted once. - text_
root ⚠ - The root owned
Textbehindtext, and the absolute offset at whichtext’s own bytes begin inside it. - text_
str ⚠ - Read a
TextPayloadas a&str, following slice owners.