Skip to main content

Module text

Module text 

Source
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 another Text (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§

OwnedText
An owned UTF-8 payload and the number of Unicode scalars in it, computed on first demand (ADR-115).
SourceSlice
A validated zero-copy view of owner’s bytes over [start, start + len).

Enums§

TextPayload
The Text payload: either an owned UTF-8 string or a zero-copy slice into another Text (the input buffer) (§4.3, §7.10, ADR-013).

Statics§

TEXT
Descriptor for the Text scalar (§4.3). Handles both owned and source-slice payloads (ADR-013). A single descriptor serves all Text values.

Functions§

text_ascii_bytes
The bytes of payload when a byte index into them is a character index — that is, when every scalar in the text is one byte wide — and None otherwise.
text_bytes
Read the UTF-8 bytes of a TextPayload, following slice owners.
text_char_count
The number of Unicode scalars in payloadt.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 Text behind text, and the absolute offset at which text’s own bytes begin inside it.
text_str
Read a TextPayload as a &str, following slice owners.