#[repr(transparent)]pub struct VaList<'a> {
inner: VaListInner,
_marker: PhantomCovariantLifetime<'a>,
}c_variadic #44930)Expand description
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.
Fields§
§inner: VaListInnerc_variadic #44930)_marker: PhantomCovariantLifetime<'a>c_variadic #44930)Implementations§
Source§impl<'f> VaList<'f>
impl<'f> VaList<'f>
Sourcepub const unsafe fn arg<T: VaArgSafe>(&mut self) -> T
🔬This is a nightly-only experimental API. (c_variadic #44930)
pub const unsafe fn arg<T: VaArgSafe>(&mut self) -> T
c_variadic #44930)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.
Trait Implementations§
Auto Trait Implementations§
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>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type #102070)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read more