Mojo struct
Formatter
A Formatter
is used by types implementing the Formattable
trait to write bytes to the underlying formatter output buffer or stream.
Implemented traits
AnyType
Methods
__init__
__init__[F: ToFormatter](inout self: Self, inout output: F)
Construct a new Formatter
from a value implementing ToFormatter
.
Parameters:
- F (
ToFormatter
): The type that supports being used to back aFormatter
.
Args:
- output (
F
): Value to accumulate or process output streamed to theFormatter
.
__init__(inout self: Self, *, fd: FileDescriptor)
Constructs a Formatter
that writes to the given file descriptor.
Args:
- fd (
FileDescriptor
): The file descriptor to write to.
__init__(inout self: Self, func: fn(UnsafePointer[NoneType, 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1], StringRef) -> None, arg: UnsafePointer[NoneType, 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1])
Constructs a formatter from any closure that accepts StringRef
s.
This function should only be used by low-level types that wish to accept streamed formatted data.
Args:
- func (
fn(UnsafePointer[NoneType, 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1], StringRef) -> None
): Raw closure function pointer. - arg (
UnsafePointer[NoneType, 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1]
): Opaque user data argument that is passed to the closure function pointer.
__moveinit__
__moveinit__(inout self: Self, owned other: Self)
Move this value.
Args:
- other (
Self
): The value to move.
write_str
write_str(inout self: Self, str_slice: StringSlice[is_mutable, lifetime])
Write a string slice to this formatter.
Args:
- str_slice (
StringSlice[is_mutable, lifetime]
): The string slice to write to this formatter. Must NOT be null terminated.
write
write[*Ts: Formattable](inout self: Self, *args: *Ts)
Write a sequence of formattable arguments to the provided formatter.
Parameters:
- *Ts (
Formattable
): Types of the provided argument sequence.
Args:
- *args (
*Ts
): Sequence of arguments to write to this formatter.
stdout
static stdout() -> Self
Constructs a formatter that writes directly to stdout.
Returns:
A formatter that writes provided data to the operating system standard output stream.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!