DelimitedView
Mojo struct 🡭
DelimitedView
Section titled “DelimitedView”@memory_onlystruct DelimitedView[O: Origin[mut=O.mut], MAX: Int = 64]A non-owning view over one delimited row.
Holds a Span into the reader’s internal buffer and a stack-allocated
FieldOffsets. No heap allocation is made.
Lifetime contract: the view is invalidated the moment LineIterator
advances (i.e. on the next next_line() call or any buffer compaction).
Never store a DelimitedView; call .to_record() if you need
the record to outlive the current iteration step.
Not thread-safe — the backing span is a raw pointer into the reader buffer.
Parameters
Section titled “Parameters”- O (
Origin) - MAX (
Int)
Implemented traits
Section titled “Implemented traits”AnyType, ImplicitlyDestructible, Movable, Sized, Writable
Methods
Section titled “Methods”__init__
Section titled “__init__”def __init__(out self, line: Span[UInt8, O], delimiter: UInt8)Args:
- line (
Span) - delimiter (
UInt8) - self (
Self)
Returns:
Self
num_fields
Section titled “num_fields”def num_fields(self) -> IntArgs:
- self (
Self)
Returns:
Int
__len__
Section titled “__len__”def __len__(self) -> IntArgs:
- self (
Self)
Returns:
Int
get_span
Section titled “get_span”def get_span(self, idx: Int) -> Span[UInt8, O]Zero-copy view of field idx. Same lifetime as this view.
Args:
- self (
Self) - idx (
Int)
Returns:
Span
def get(self, idx: Int) -> Optional[Span[UInt8, O]]Args:
- self (
Self) - idx (
Int)
Returns:
Optional
to_record
Section titled “to_record”def to_record(deinit self) -> DelimitedRecord[MAX]Copy the backing bytes and offsets into an owned DelimitedRecord.
One BString allocation; offsets are copied by value (stack to stack).
Call this when the record must outlive the current iteration step.
Args:
- self (
Self)
Returns:
DelimitedRecord
write_to
Section titled “write_to”def write_to[w: Writer](self, mut writer: w)Parameters:
- w (
Writer)
Args:
- self (
Self) - writer (
w)