Mojo struct
WritableVariadicPack
@register_passable
struct WritableVariadicPack[mut: Bool, //, origin: Origin[mut], pack_origin: Origin[mut], *Ts: Writable]
Wraps a VariadicPack
, enabling it to be passed to a writer along with extra arguments.
Example:
from utils.write import WritableVariadicPack
fn foo[*Ts: Writable](*messages: *Ts):
print("message:", WritableVariadicPack(messages), "[end]")
x = 42
foo("'x = ", x, "'")
from utils.write import WritableVariadicPack
fn foo[*Ts: Writable](*messages: *Ts):
print("message:", WritableVariadicPack(messages), "[end]")
x = 42
foo("'x = ", x, "'")
Output:
message: 'x = 42' [end]
message: 'x = 42' [end]
Parameters
- mut (
Bool
): Whether the origin is mutable. - origin (
Origin[mut]
): The origin of the reference to theVariadicPack
. - pack_origin (
Origin[mut]
): The origin of theVariadicPack
. - *Ts (
Writable
): The types of the variadic arguments conforming toWritable
.
Fields
- value (
Pointer[VariadicPack[pack_origin, Writable, Ts], origin]
): Reference to aVariadicPack
that comforms toWritable
.
Implemented traits
AnyType
,
Copyable
,
ExplicitlyCopyable
,
Movable
,
UnknownDestructibility
,
Writable
Methods
__init__
__init__(ref [origin] value: VariadicPack[pack_origin, Writable, Ts]) -> Self
Initialize using a reference to the VariadicPack
.
Args:
- value (
VariadicPack[pack_origin, Writable, Ts]
): TheVariadicPack
to take a reference to.
write_to
write_to[W: Writer](self, mut writer: W)
Formats the string representation of all the arguments in the VariadicPack
to the provided Writer
.
Parameters:
- W (
Writer
): A type conforming to the Writable trait.
Args:
- writer (
W
): The type conforming toWritable
.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!