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 byi64(1-based, converted to 0-based internally)HashMap<K, V>: Indexed by keyK(pass-through semantics)HashMap<String, V>: Also supports&strkeys 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§
- Logos
GetChar - Zero-allocation character access for string comparisons.
- Logos
Index - Immutable element access by index.
- Logos
Index Mut - Mutable element access by index.
- Logos
Items - 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
lenitems, orNonewhen 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_throughfor a loop that stops beforestop(while i < stop).- logos_
run_ through - The items a counted loop over the indices
firstthroughlastreads from a sequence oflenitems, in order, as the 0-based range they occupy: empty whenfirstis pastlast, and otherwise the stopresolve_logos_indexmakes 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 endnames in a sequence oflenitems, or an empty range when the slice reaches outside it (or runs backwards). ONE definition, likelogos_offset, and 64-bit on every target. - logos_
text_ run_ before logos_text_run_throughfor a loop that stops beforestop.- logos_
text_ run_ through - The text a counted loop produces when it copies bytes
firstthroughlastofsinto a sequence and reads them back withtext_from_bytes: the bytes underlogos_run_through, and the stoptext_from_bytesmakes 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.