/// appends zeroes to the end of the string and converts it into a pointer /// useful for quick ffi pub macro cstr($str:expr) { concat!($str,"\0\0").as_ptr() as *const _ } /// utility macro for inline c functions /// /// | macro | rust | /// |-----------|----------| /// | ```cfn!( () -> usize )``` | ``` extern "C" fn() -> usize``` | /// | ```cfn!( (usize) -> usize )``` | ``` extern "C" fn(usize) -> usize``` | /// | ```cfn!( (usize) )``` | ``` extern "C" fn(usize)``` | /// | ```cfn!( (u32, usize, usize) -> u32 )``` | ``` extern "C" fn(u32, usize, usize) -> u32``` | pub macro cfn($str:expr) { ( ($($t:ty),*)) => { extern "C" fn($( $t ),* ) }; ( ($($t:ty),*) -> $r:ty) => { extern "C" fn($( $t ),* ) -> $r } } #[inline(always)] pub fn _chain_helper(address: usize, links: [usize;N]) -> usize { links.iter().fold(address, |b,r| unsafe {*((b + *r) as *const usize)} ) } #[allow(unused)] use crate::cast_traits::As; pub macro ptr_chain( $base:expr, $($link:expr),* ) { _chain_helper(As::::cast($base), [ $(As::::cast($link)),* ]) }