va_list/
wrapper.rs

1
2use super::imp;
3
4/// Rust version of C's `va_list` type from the `stdarg.h` header
5#[repr(transparent)]
6pub struct VaList<'a> {
7    internal: imp::VaList<'a>,
8}
9
10/// Core type as passed though the FFI
11impl<'a> VaList<'a> {
12    /// Read a value from the VaList.
13    ///
14    /// Users should take care that they are reading the correct type
15    pub unsafe fn get<T: VaPrimitive>(&mut self) -> T {
16        T::get(&mut self.internal)
17    }
18}
19
20/// Trait implemented on types that can be read from a va_list
21pub trait VaPrimitive: 'static {
22    #[doc(hidden)]
23    unsafe fn get(_: &mut imp::VaList) -> Self;
24}
25
26#[allow(dead_code)]
27mod check_core_types {
28	struct Foo<T: super::VaPrimitive>([T;0]);
29
30	struct Checks {
31		_ptr: Foo<*const u8>,
32		_usize: Foo<usize>,
33		_isize: Foo<isize>,
34	}
35}
36