-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17dae11
commit 3ee5e86
Showing
33 changed files
with
840 additions
and
502 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// Copyright (c) 2017, 2020 ADLINK Technology Inc. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ADLINK zenoh team, <zenoh@adlink-labs.tech> | ||
// | ||
|
||
#[macro_export] | ||
macro_rules! dispatch_fn { | ||
() => {}; | ||
(async fn $fn_name:ident(&self $(, $($p_name:ident: $p_type:ty),*)? $(,)? ) $(-> $r_type:ty)?; $($tail:tt)*) => { | ||
pub(crate) async fn $fn_name(&self $(, $($p_name: $p_type),*)? ) $(-> $r_type)? { | ||
dispatch!(self {this => this.$fn_name($($($p_name),*)? ).await}) | ||
} | ||
dispatch_fn!($($tail)*); | ||
}; | ||
(fn $fn_name:ident(&self $(, $($p_name:ident: $p_type:ty),*)? $(,)? ) $(-> $r_type:ty)?; $($tail:tt)*) => { | ||
pub(crate) fn $fn_name(&self $(, $($p_name: $p_type),*)? ) $(-> $r_type)? { | ||
dispatch!(self {this => this.$fn_name($($($p_name),*)? )}) | ||
} | ||
dispatch_fn!($($tail)*); | ||
}; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! dispatcher { | ||
($d:ident ( | ||
$($(#[$meta:meta])* | ||
$impl_name:ident($impl_type:ty)),* $(,)? | ||
) { | ||
$($body:tt)* | ||
}) => { | ||
#[allow(dead_code)] | ||
#[derive(Clone)] | ||
pub enum $d { | ||
$($(#[$meta])* | ||
$impl_name($impl_type)),* | ||
} | ||
|
||
macro_rules! dispatch { | ||
($i:ident {$t:ident => $e:expr}) => ( | ||
match $i { | ||
$($(#[$meta])* | ||
$d::$impl_name($t) => $e),* | ||
} | ||
) | ||
} | ||
|
||
#[allow(dead_code)] | ||
impl $d { | ||
dispatch_fn!($($body)*); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.