#[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.next_arg::<i32>() };
}
sum
}
assert_eq!(unsafe { my_func(1, 42i32) }, 42);
assert_eq!(unsafe { my_func(3, 42i32, -7i32, 20i32) }, 55);The VaList::next_arg method reads the next argument from the variable argument list,
and is equivalent to C 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.
A VaList can be used across an FFI boundary, and fully matches the platform’s va_list in
terms of layout and ABI.
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 next_arg<T: VaArgSafe>(&mut self) -> T
🔬This is a nightly-only experimental API. (c_variadic #44930)
pub const unsafe fn next_arg<T: VaArgSafe>(&mut self) -> T
c_variadic #44930)Read the next argument from the variable argument list.
Only types that implement VaArgSafe can be read from a variable argument list.
§Safety
This function is safe to call only if all of the following conditions are satisfied:
- There is another c-variadic argument to read.
- The actual type of the argument
Uis compatible withT(as defined below). - If
UandTare both integer types, then the value passed by the caller must be representable in both types.
Types T and U are compatible when:
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