Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- macro_rules! indices {
- ([] $($rest:tt)*) =>
- { indices!($($rest)* []) };
- ([$x1:tt] $($rest:tt)*) =>
- { indices!($($rest)* [0]) };
- ([$x1:tt $x2:tt] $($rest:tt)*) =>
- { indices!($($rest)* [0 1]) };
- ([$x1:tt $x2:tt $x3:tt] $($rest:tt)*) =>
- { indices!($($rest)* [0 1 2]) };
- // etc
- ($cb:ident: $($args:tt)*) =>
- { $cb!( $($args)* ) };
- }
- macro_rules! defer {
- ($c:expr, $i:ident( $( $x:expr ),* )) => {{
- indices!([$(($x))*] defer_aux: $c, $i $( , $x )*; );
- }}
- }
- macro_rules! defer_aux {
- ($c:expr, $i:ident $(, $x:expr )*; [$( $xi:tt )*]) => {{
- let tup = ( $( $x, )* );
- $c.defer(move |c| $i(c $(, tup . $xi)*));
- }}
- }
- struct Core {}
- impl Core {
- fn defer<F>(&mut self, _f: F) where F: FnOnce(&mut Core) + 'static {}
- }
- fn test(_core: &mut Core, _v1: i32, _v2: i32) {}
- fn main() {
- let mut core = Core {};
- defer!(&mut core, test(1, 2));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement