102 lines
1.9 KiB
Rust
102 lines
1.9 KiB
Rust
#![feature(unboxed_closures)]
|
|
#![feature(fn_traits)]
|
|
|
|
macro_rules! itt {
|
|
() => {
|
|
()
|
|
};
|
|
|
|
($name:ident) => {
|
|
($name,)
|
|
};
|
|
|
|
($($name:ident),+$(,)?) => {
|
|
($($name),+)
|
|
};
|
|
}
|
|
|
|
macro_rules! ttt {
|
|
() => {
|
|
()
|
|
};
|
|
|
|
($type:ty) => {
|
|
($type,)
|
|
};
|
|
|
|
($($type:ty),+$(,)?) => {
|
|
($($type),+)
|
|
};
|
|
}
|
|
|
|
macro_rules! tou {
|
|
() => {
|
|
()
|
|
};
|
|
|
|
($type:ty) => {
|
|
$type
|
|
};
|
|
}
|
|
|
|
macro_rules! overloaddddddd {
|
|
($type:tt {
|
|
$(
|
|
($($name:ident: $arg:ty),*) $(-> $ret:ty)? {
|
|
$body:expr
|
|
}
|
|
)*
|
|
}) => {
|
|
#[allow(non_camel_case_types)]
|
|
struct $type;
|
|
|
|
$(
|
|
impl FnOnce<ttt!($($arg),*)> for $type
|
|
where
|
|
$type: std::ops::Fn<ttt!($($arg),*)>,
|
|
{
|
|
type Output = tou!($($ret)?);
|
|
|
|
extern "rust-call" fn call_once(self, args: ttt!($($arg),*)) -> Self::Output {
|
|
self.call(args)
|
|
}
|
|
}
|
|
|
|
impl FnMut<ttt!($($arg),*)> for $type
|
|
where
|
|
$type: std::ops::Fn<ttt!($($arg),*)>,
|
|
{
|
|
extern "rust-call" fn call_mut(&mut self, args: ttt!($($arg),*)) -> Self::Output {
|
|
self.call(args)
|
|
}
|
|
}
|
|
|
|
impl Fn<ttt!($($arg),*)> for $type {
|
|
extern "rust-call" fn call(&self, itt!($($name),*): ttt!($($arg),*)) -> Self::Output {
|
|
$body
|
|
}
|
|
}
|
|
)*
|
|
};
|
|
}
|
|
|
|
overloaddddddd!(cursed {
|
|
(name: String) {{
|
|
println!("{name}")
|
|
}}
|
|
|
|
(num: usize) -> usize {{
|
|
println!("{num}");
|
|
num + 1
|
|
}}
|
|
|
|
() {{
|
|
println!("No arguments?");
|
|
}}
|
|
});
|
|
|
|
fn main() {
|
|
cursed("test".to_string());
|
|
println!("{}", cursed(1337usize));
|
|
cursed();
|
|
}
|