1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/// Creates a virtual method table.
/// # Behaviour
/// Each time macro is used, it will create new virtual method table via [`Box::leak`].
/// ```
/// # use faithe::vmt
/// fn first() {
/// println!("First");
/// }
/// fn second() {
/// println!("Second");
/// }
///
/// let vmt = vmt! {
/// first,
/// second
/// };
/// ```
#[macro_export]
macro_rules! vmt {
(
$var:ident => [
$($fn:ident),*
]
) => {
*core::mem::transmute::<_, *mut usize>(&$var) = Box::leak(
Box::new(
[
$($fn as usize),*
]
)
).as_ptr() as usize
};
}