Search results

There are no results.

std.fmt.TupleFormatter

type pub TupleFormatter

A type for making it easy to format tuple-like values, such as tuples and enums.

Instance methods

field

Show source code
Hide source code
fn pub mut field[T: Format](value: ref T) -> mut TupleFormatter {
  match @fields {
    case 0 -> @formatter.write('(')
    case _ -> @formatter.write(', ')
  }

  @formatter.descend(fn { value.fmt(@formatter) })
  @fields += 1
  self
}
fn pub mut field[T: Format](value: ref T) -> mut TupleFormatter

Adds a new formatted field to the output.

finish

Show source code
Hide source code
fn pub mut finish {
  match @fields {
    case 0 if @named -> {}
    case 0 -> @formatter.write('()')
    case _ -> @formatter.write(')')
  }
}
fn pub mut finish

Finishes formatting the tuple.

This method is used instead of a Drop implementation, otherwise a call chain (e.g. x.tuple('').field(10)) results in a drop error, as the final reference returned by field would outlive the TupleFormatter.