variadic_arguments
import std::core::variadic_arguments; — in the prelude · source
Types
VariadicArguments
type struct VariadicArguments {
private ptr: void*;
}
A function declared with a trailing args... bucket mirrors C's variadic calling convention, which keeps it ABI-compatible for printf-style interop. The compiler emits va_start/va_end around the body and binds args to the raw va_list. VariadicArguments wraps that pointer so you can read typed values without hand-rolling va_arg:
function logf(format: string, args...) -> void {
mut va: VariadicArguments = VariadicArguments::new(args);
const count: i32 = va.next(); // T inferred as i32
const name: string = va.next();
}
as_pointer() hands back the raw va_list for forwarding the rest to a C v*-family function such as vfprintf.
Two limits come from C varargs and no wrapper can fix them. It is not count-safe — nothing records how many arguments were passed or their types, so the callee has to know out of band (a format string, a leading count, a sentinel). And the default argument promotions apply: a variadic call promotes i8, i16, and boolean to i32, and f32 to f64. VariadicArgument is therefore implemented only for the promoted set, and va.next::<i8>() is a compile error by design — read it as i32 and narrow.
Constructors
static new(va: void*) -> VariadicArguments;
static new(va: void*) -> VariadicArguments;Wrap a variadic body's args bucket: VariadicArguments::new(args). va is the raw va_list pointer the compiler binds for the args... parameter.
Methods
as_pointer(&this) -> void*;
as_pointer(&this) -> void*;The raw va_list pointer, for forwarding the remaining arguments to a C v*-family function (vfprintf, vsnprintf, ...). Equivalent to passing the original args identifier.
![implicit]next<T>(&this) -> T where T: VariadicArgument;
![implicit]next<T>(&this) -> T where T: VariadicArgument;Read the next variadic argument as T (one of the promoted scalar types), advancing the list. ![implicit] lets the type be recovered from the call's expected type, so const n: i64 = va.next(); works; va.next<i64>() is the explicit form.
Trait implementations
implement trait Copy for VariadicArguments
implement trait Drop for VariadicArguments
VariadicArgument
type trait VariadicArgument {
static __pluck(p: void*) -> This;
}
The trait next<T> dispatches through. It is implemented for exactly the types that survive C's default argument promotions, which is why va.next::<i8>() is a compile error rather than a silent misread.
Constructors
static __pluck(p: void*) -> This;
static __pluck(p: void*) -> This;Read the next argument of type This from the va_list p points at, advancing it. p is the raw va_list pointer (VariadicArguments::as_pointer).
Implementors
implement trait VariadicArgument for i32
implement trait VariadicArgument for u32
implement trait VariadicArgument for i64
implement trait VariadicArgument for u64
implement trait VariadicArgument for f64
implement trait VariadicArgument for string
type struct Name { ... }
type enum Name { ... }
type trait Name { ... }
type union Name { ... }Begins a type declaration; the keyword that follows says which kind. On its own, type Name = Existing; declares an alias.
type struct Name {
field: Type;
method(&this) -> Ret { ... }
}A value type with named fields and optional methods. Structs live on the stack and are passed by value. Fields are public by default and may carry = default values; methods take their receiver as &this, mut &this, or this.
type struct VariadicArguments {}Single-pointer wrapper over the active va_list. ptr is the raw va_list pointer - the args identifier the compiler binds in a variadic body.
private type struct Name { ... }
private:Confined to the module that declares it - for items and members alike. A private field or function reached from another module is E0353, and a private type named there is E0503. private: opens a block of such members.
VariadicArguments.ptr: void*function name<T>(param: Type) -> Ret { ... }Declares a function. Parameters are written name: Type and are never inferred; the return type follows -> and defaults to void. Declaration order does not matter: every signature is collected before any body is checked, so functions may call each other freely and recurse.
function logf(format: string, args...) -> void(parameter) format: stringprimitive stringNUL-terminated raw string (u8*), matching the C ABI. Length-typed text is Str / String.
(parameter) argsfunction name(count: i32, args...)A variadic parameter: the trailing bucket receives any number of further arguments with C's calling convention, so the function stays ABI-compatible with the printf family. Wrap the bucket in VariadicArguments to read typed values from it.
mut name: Type = value;A mutable binding, reassignable after declaration - mutability is opt-in, const is the default. At module level it declares mutable global state. Before & it marks an exclusive reference or receiver instead.
mut va: VariadicArgumentstype struct VariadicArguments {}Single-pointer wrapper over the active va_list. ptr is the raw va_list pointer - the args identifier the compiler binds in a variadic body.
static VariadicArguments::new(va: void*) -> VariadicArgumentsWrap a variadic body's args bucket: VariadicArguments::new(args). va is the raw va_list pointer the compiler binds for the args... parameter.
(parameter) argsconst name: Type = value;An immutable binding: it cannot be reassigned after initialisation. The annotation may be omitted when an initialiser is present - the binding takes the initialiser's concrete type, inferred locally. Mutability is opt-in through mut.
const count: i32mut va: VariadicArgumentsVariadicArguments::next<T>(&this) -> T
where T: VariadicArgumentRead the next variadic argument as T (one of the promoted scalar types), advancing the list. ![implicit] lets the type be recovered from the call's expected type, so const n: i64 = va.next(); works; va.next<i64>() is the explicit form.
const name: stringtype trait Name : Base {
method(&this, other: &This) -> Ret;
}Names a set of methods a type may implement. Inside the body This is the implementing type; methods may carry default bodies, and a trait may require a base trait (type trait Ord : Eq). Generic code asks for a trait with where T: Name.
type trait VariadicArgument {
static __pluck(p: void*) -> This;
}A type that can be read as the next variadic argument, and so passed as one. Implemented for the C-promoted scalar set only (see the module note): a variadic call refuses an argument past its declared parameters whose type does not implement it, unless that argument is a pointer.
static name(param: Type) -> Ret { ... }A method that belongs to the type rather than an instance, called as Type::name(..). For structs, static new(..) returning a struct literal is the idiomatic constructor.
static VariadicArgument::__pluck(p: void*) -> ThisRead the next argument of type This from the va_list p points at, advancing it. p is the raw va_list pointer (VariadicArguments::as_pointer).
(parameter) p: void*ThisThe implementing type, inside a trait or implement body. other: &This in a trait method is a reference to whichever type implements it; This::Item names an associated type.
import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
namespace std::core::variadic_arguments;VariadicArguments: a safe, typed wrapper over a C-ABI variadic argument list.
module pageVariadicArguments::as_pointer(&this) -> void*The raw va_list pointer, for forwarding the remaining arguments to a C v*-family function (vfprintf, vsnprintf, ...). Equivalent to passing the original args identifier.
type trait VariadicArgument {
static __pluck(p: void*) -> This;
}A type that can be read as the next variadic argument, and so passed as one. Implemented for the C-promoted scalar set only (see the module note): a variadic call refuses an argument past its declared parameters whose type does not implement it, unless that argument is a pointer.
std::core::variadic_arguments(parameter) va: void*function args() -> Array<String>Program arguments as UTF-8 strings. The first element is the program name. On Windows the runtime splits the wide command line before main runs and transcodes it, so non-ASCII arguments arrive intact and a lone surrogate in one reads as U+FFFD. Returns an empty array if the runtime hasn't published argv yet.
&this
mut &this
thisThe receiver of a method. Its first parameter declares how the method takes it: &this borrows read-only, mut &this borrows exclusively, and this / mut this move the value in and consume it. In the body, this.field reaches the members.
where T: Ord + Clone, U: HashConstrains generic parameters to types that implement the listed traits, which is what makes those traits' methods callable on T. Bounds on one parameter join with +; parameters separate with ,. A where on a single method narrows the type's parameter for that method only.
const NAME: Type = value;At module level, a true compile-time constant, conventionally SCREAMING_SNAKE_CASE. (mut at module level declares mutable global state instead.)
const n: i64implement struct Name { ... }
implement trait Trait for Type { ... }
implement u64 { ... }Adds methods to a type outside its declaration. implement struct T (or enum, or a bare primitive) opens an inherent block; implement trait Tr for T supplies a trait's methods for one type. Resolution is at compile time - no dynamic dispatch.
implement trait Trait for Type { ... }Introduces a trait implementation: the block supplies, for one concrete type, the method bodies the trait requires.
language referencetype trait Copy {}Types whose values can be duplicated by a bitwise copy. Integers, floats, pointers, and pure-POD structs qualify; anything that owns resources (heap storage, file handles, refcount) does not.
std::core::markerimplement trait Trait for Type { ... }Names the type a trait implementation is for. The block that follows supplies the bodies the trait requires.
language referencetype trait Drop {
drop(mut &this) -> void;
}A type that releases something when a value of it ends: memory, a file handle, a lock. The compiler calls drop once when an owned value goes out of scope; release a value early with mem::drop(value).
static VariadicArgument::__pluck(p: void*) -> ThisRead the next argument of type This from the va_list p points at, advancing it. p is the raw va_list pointer (VariadicArguments::as_pointer).