Crates.io | variyak |
lib.rs | variyak |
version | 0.2.0 |
source | src |
created_at | 2021-03-11 19:50:48.704406 |
updated_at | 2021-04-06 19:01:43.085246 |
description | macro to help call variadic functions given a container such as a Vec |
homepage | |
repository | https://github.com/sharksforarms/variyak |
max_upload_size | |
id | 367401 |
size | 25,586 |
This crate provides a macro call_variadic
which can be used to construct boilerplate code
to call variadic functions using data from a container such as a Vec.
Example:
#![feature(c_variadic)]
use variyak::call_variadic;
fn main() {
let data = vec![1, 2];
let arg = 0;
mod test {
#[no_mangle]
pub unsafe extern "C" fn my_func(_fixed: u32, mut _args: ...) -> bool {
true
}
}
unsafe {
assert!(call_variadic!(
test::my_func(arg, ...) // function to call, `...` is the variadic arguments
data, // container identifier
n, // index identifier
data[n], // argument expression: get `argument` at index `n`
2, // maximum number of arguments to expand
));
}
unsafe {
use test::my_func;
assert!(call_variadic!(my_func(arg, ...), data, n, data[n], 2));
assert!(call_variadic!(my_func(arg, ...), data, n, data[n], 2));
assert!(call_variadic!(my_func(arg, arg, ..., arg), data, n, data[n], 2));
assert!(call_variadic!(my_func(arg, ..., arg), data, n, data[n], 2));
assert!(call_variadic!(my_func(arg, 42 + 27, ..., arg, 10usize), data, n, data[n], 2));
};
}