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[mut=mut]]: AnyStruct[_FaiParserRecordIter[R, origin]] = _FaiParserRecordIter[R, origin]
  • R (Reader)

AnyType, ImplicitlyDestructible, Iterable, Movable

fn __init__(out self, var reader: R)

Args:

  • reader (R)
  • self (Self)

Returns:

Self

Raises:

fn has_more(self) -> Bool

Args:

  • self (Self)

Returns:

Bool

fn 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[MutExternalOrigin]

Raises:

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

fn 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).

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

Read all rows from this index into memory.

Args:

  • self (Self)

Returns:

List[FaiRecord]

Raises:

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

Iterator yielding zero-alloc FaiViews.

Args:

  • self (Self)

Returns:

_FaiParserViewIter[R, origin_of(self)]

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

Iterator yielding owned FaiRecords.

Args:

  • self (Self)

Returns:

_FaiParserRecordIter[R, origin_of(self)]

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

Args:

  • self (Self)

Returns:

_FaiParserRecordIter[R, origin_of(self)]