https://github.com/sharksforarms/variyak
macro to call variadic functions using data from a container
https://github.com/sharksforarms/variyak
rust-macro variadic
Last synced: 4 months ago
JSON representation
macro to call variadic functions using data from a container
- Host: GitHub
- URL: https://github.com/sharksforarms/variyak
- Owner: sharksforarms
- License: apache-2.0
- Created: 2021-03-11T14:23:43.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-06T19:01:00.000Z (almost 5 years ago)
- Last Synced: 2025-08-23T18:21:37.600Z (6 months ago)
- Topics: rust-macro, variadic
- Language: Rust
- Homepage:
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Variyak
[](https://crates.io/crates/variyak)
[](https://docs.rs/variyak)
[](https://github.com/sharksforarms/variyak/actions)
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:
```rust
#![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));
};
}
```