Skip to main content
Log in

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 the VariadicPack.
  • pack_origin (Origin[mut]): The origin of the VariadicPack.
  • *Ts (Writable): The types of the variadic arguments conforming to Writable.

Fields

  • value (Pointer[VariadicPack[pack_origin, Writable, Ts], origin]): Reference to a VariadicPack that comforms to Writable.

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]): The VariadicPack 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 to Writable.