Skip to content

DelimitedView

Mojo struct 🡭

@memory_only
struct 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.

  • O (Origin)
  • MAX (Int)

AnyType, ImplicitlyDestructible, Movable, Sized, Writable

def __init__(out self, line: Span[UInt8, O], delimiter: UInt8)

Args:

  • line (Span)
  • delimiter (UInt8)
  • self (Self)

Returns:

Self

def num_fields(self) -> Int

Args:

  • self (Self)

Returns:

Int

def __len__(self) -> Int

Args:

  • self (Self)

Returns:

Int

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

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

def write_to[w: Writer](self, mut writer: w)

Parameters:

  • w (Writer)

Args:

  • self (Self)
  • writer (w)