This commit is contained in:
itamar 2026-03-20 18:39:35 +00:00
commit cc32de6e5a
Signed by: itamar
GPG key ID: C494AC33A201F9E4

102
file.rs Normal file
View file

@ -0,0 +1,102 @@
#![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();
}