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!
If you'd like to share more information, please report an issue on GitHub
π What went wrong?