#[macro_export]
macro_rules! cb {
($owner:expr, |$arg_name:ident| async $method:ident ( $($args:tt)* )) => {
$crate::Callback::new_async_rc($owner, move |obj, $arg_name| {
let obj = obj.clone();
async move { obj.$method($($args)*).await }
})
};
($owner:expr, async $method:ident ( $($args:tt)* )) => {
$crate::Callback::new_async_rc($owner, move |obj, arg| {
let obj = obj.clone();
let arg = arg;
async move { obj.$method($($args)*).await }
})
};
($owner:expr, async $method:ident) => {
$crate::Callback::new_async_rc($owner, move |obj, _| {
let obj = obj.clone();
async move { obj.$method().await }
})
};
($owner:expr, |$arg_name:ident| $method:ident ( $($args:tt)* )) => {
$crate::Callback::new_sync_rc($owner, move |obj, $arg_name| {
let obj = obj.clone();
obj.$method($($args)*)
})
};
($owner:expr, $method:ident ( $($args:tt)* )) => {
$crate::Callback::new_sync_rc($owner, move |obj, arg| {
let obj = obj.clone();
let arg = arg;
obj.$method($($args)*)
})
};
($owner:expr, $method:ident) => {
$crate::Callback::new_sync_rc($owner, move |obj, _| {
let obj = obj.clone();
obj.$method()
})
};
}