Skip to content

FaiParser

Mojo struct 🡭

@memory_only
struct FaiParser[R: Reader]

Streaming parser for .fai index files over a Reader.

API: - next_view()FaiView (zero-alloc; invalidated on next advance) - next_record()FaiRecord (materialized; raises EOFError when exhausted) - for rec in parser / records()FaiRecord (standard iteration) - for view in parser.views()FaiView (zero-alloc iteration) - collect()List[FaiRecord] (helper that reads the whole index)

  • IteratorType[origin: Origin]: AnyStruct[_FaiParserRecordIter[R, origin]] = _FaiParserRecordIter[R, origin]
  • R (Reader)

AnyType, ImplicitlyDestructible, Iterable, Movable

def __init__(out self, var reader: R)

Args:

  • reader (R)
  • self (Self)

Returns:

Self

Raises:

def has_more(self) -> Bool

Args:

  • self (Self)

Returns:

Bool

def next_view(mut self) -> FaiView[MutExternalOrigin]

Return the next FAI index row as a zero-alloc FaiView.

The view borrows from the reader’s buffer and is invalidated on the next call to any advancing method. Call .to_record() when you need an owned FaiRecord.

Args:

  • self (Self)

Returns:

FaiView

Raises:

EOFError: When no more records are available. Error: On malformed input (wrong column count, non-integer fields).

def next_record(mut self) -> FaiRecord

Return the next FAI index row as a FaiRecord.

Convenience wrapper around next_view().to_record().

Args:

  • self (Self)

Returns:

FaiRecord

Raises:

EOFError: When no more records are available. Error: On malformed input (wrong column count, non-integer fields).

def collect(mut self) -> List[FaiRecord]

Read all rows from this index into memory.

Args:

  • self (Self)

Returns:

List

Raises:

def views(ref self) -> _FaiParserViewIter[R, origin_of(self)]

Iterator yielding zero-alloc FaiViews.

Args:

  • self (Self)

Returns:

_FaiParserViewIter

def records(ref self) -> _FaiParserRecordIter[R, origin_of(self)]

Iterator yielding owned FaiRecords.

Args:

  • self (Self)

Returns:

_FaiParserRecordIter

def __iter__(ref self) -> _FaiParserRecordIter[R, origin_of(self)]

Args:

  • self (Self)

Returns:

_FaiParserRecordIter