Skip to main content

Module indexing

Module indexing 

Source
Expand description

Polymorphic indexing traits for Logos collections.

Logos uses 1-based indexing to match natural language conventions. These traits provide get/set operations that automatically convert 1-based indices to 0-based for underlying Rust collections.

§Supported Collections

  • Vec<T>: Indexed by i64 (1-based, converted to 0-based internally)
  • HashMap<K, V>: Indexed by key K (pass-through semantics)
  • HashMap<String, V>: Also supports &str keys for convenience

§Panics

Vector indexing operations panic if the index is out of bounds (less than 1 or greater than collection length). Map operations panic if the key is not found.

Traits§

LogosGetChar
Zero-allocation character access for string comparisons.
LogosIndex
Immutable element access by index.
LogosIndexMut
Mutable element access by index.
LogosItems
Borrowing access to the item a 1-based LOGOS index names, under resolve_logos_index. A generated program reads and writes a sequence’s items through this, so its fast path costs one compare and every other index means what it means on the interpreter.

Functions§

logos_offset
The 0-based offset of the item a 1-based LOGOS index names in a sequence of len items, or None when it names none. Index 1 is the first item and a negative index counts from the back (-1 is the last); 0 and anything past either end name nothing. ONE definition: every engine, every generated program and every fast path indexes through this rule. The arithmetic is 64-bit on every target, so a wasm32 build reads the same item a native one does.
logos_run_before
logos_run_through for a loop that stops before stop (while i < stop).
logos_run_through
The items a counted loop over the indices first through last reads from a sequence of len items, in order, as the 0-based range they occupy: empty when first is past last, and otherwise the stop resolve_logos_index makes at the first index in the loop’s order that names no item. A backend that copies such a loop in one step copies this range, so it reads what the loop reads and stops where the loop stops. (A run that crosses 0 always stops at 0; one wholly below 0 counts from the back.)
logos_slice_range
The 0-based range items start through end names in a sequence of len items, or an empty range when the slice reaches outside it (or runs backwards). ONE definition, like logos_offset, and 64-bit on every target.
logos_text_run_before
logos_text_run_through for a loop that stops before stop.
logos_text_run_through
The text a counted loop produces when it copies bytes first through last of s into a sequence and reads them back with text_from_bytes: the bytes under logos_run_through, and the stop text_from_bytes makes when they do not form UTF-8. A slice of text is text exactly when both of its ends fall between characters, so the common case costs two boundary checks.
resolve_logos_index
logos_offset, failing with the one sentence every tier reports when the index names no item.