Struct VaList

struct VaList<'a> { ... }

A variable argument list, ABI-compatible with va_list in C.

This type is created in c-variadic functions when ... is desugared. A VaList is automatically initialized (equivalent to calling va_start in C).

#![feature(c_variadic)]

use std::ffi::VaList;

/// # Safety
/// Must be passed at least `count` arguments of type `i32`.
unsafe extern "C" fn my_func(count: u32, ap: ...) -> i32 {
    unsafe { vmy_func(count, ap) }
}

/// # Safety
/// Must be passed at least `count` arguments of type `i32`.
unsafe fn vmy_func(count: u32, mut ap: VaList<'_>) -> i32 {
    let mut sum = 0;
    for _ in 0..count {
        sum += unsafe { ap.arg::<i32>() };
    }
    sum
}

assert_eq!(unsafe { my_func(1, 42i32) }, 42);
assert_eq!(unsafe { my_func(3, 42i32, -7i32, 20i32) }, 55);

The VaList::arg method can be used to read an argument from the list. This method automatically advances the VaList to the next argument. The C equivalent is va_arg.

Cloning a VaList performs the equivalent of C va_copy, producing an independent cursor that arguments can be read from without affecting the original. Dropping a VaList performs the equivalent of C va_end.

This can be used across an FFI boundary, and fully matches the platform's va_list.

Implementations

impl<'f> VaList<'f>

unsafe const fn arg<T: VaArgSafe>(self: &mut Self) -> T

Read an argument from the variable argument list, and advance to the next argument.

Only types that implement VaArgSafe can be read from a variable argument list.

Safety

This function is only sound to call when there is another argument to read, and that argument is a properly initialized value of the type T.

Calling this function with an incompatible type, an invalid value, or when there are no more variable arguments, is unsound.

impl Debug for VaList<'_>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<'a> Freeze for VaList<'a>

impl<'a> RefUnwindSafe for VaList<'a>

impl<'a> Send for VaList<'a>

impl<'a> Sync for VaList<'a>

impl<'a> Unpin for VaList<'a>

impl<'a> UnsafeUnpin for VaList<'a>

impl<'a> UnwindSafe for VaList<'a>

impl<'f> Clone for VaList<'f>

fn clone(self: &Self) -> Self

impl<'f> Drop for VaList<'f>

fn drop(self: &mut Self)

impl<T> Any for VaList<'a>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for VaList<'a>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for VaList<'a>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for VaList<'a>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for VaList<'a>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for VaList<'a>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for VaList<'a>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for VaList<'a>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>