commit cc32de6e5a3dbe5833132c78c7bb310895202919 Author: itamar Date: Fri Mar 20 18:39:35 2026 +0000 push diff --git a/file.rs b/file.rs new file mode 100644 index 0000000..56d1ff2 --- /dev/null +++ b/file.rs @@ -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 for $type + where + $type: std::ops::Fn, + { + type Output = tou!($($ret)?); + + extern "rust-call" fn call_once(self, args: ttt!($($arg),*)) -> Self::Output { + self.call(args) + } + } + + impl FnMut for $type + where + $type: std::ops::Fn, + { + extern "rust-call" fn call_mut(&mut self, args: ttt!($($arg),*)) -> Self::Output { + self.call(args) + } + } + + impl Fn 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(); +}