use macro to declare static methodinfo items
This commit is contained in:
parent
bfcba4fd86
commit
79fa17d986
|
@ -23,6 +23,7 @@ macro_rules! subdirmap {
|
|||
}
|
||||
}}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MethodInfo<'a> {
|
||||
pub get: Option<&'a ApiMethod<'a>>,
|
||||
|
@ -40,6 +41,16 @@ pub static METHOD_INFO_DEFAULTS: MethodInfo = MethodInfo {
|
|||
subdirs: None,
|
||||
};
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! methodinfo {
|
||||
($name:ident, $($option:ident => $e:expr),*) => {
|
||||
static $name: MethodInfo = MethodInfo {
|
||||
$( $option: Some($e), )*
|
||||
..METHOD_INFO_DEFAULTS
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_method_info<'a>(root: &'a MethodInfo, components: &[&str]) -> Option<&'a MethodInfo<'a>> {
|
||||
|
||||
if components.len() == 0 { return Some(root); };
|
||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -100,23 +100,23 @@ static TEST_API_METHOD: ApiMethod = ApiMethod {
|
|||
};
|
||||
|
||||
|
||||
static API3_TEST: MethodInfo = MethodInfo {
|
||||
..METHOD_INFO_DEFAULTS
|
||||
};
|
||||
methodinfo!{
|
||||
API3_TEST,
|
||||
}
|
||||
|
||||
static API3_NODES: MethodInfo = MethodInfo {
|
||||
get: Some(&TEST_API_METHOD),
|
||||
..METHOD_INFO_DEFAULTS
|
||||
};
|
||||
methodinfo!{
|
||||
API3_NODES,
|
||||
get => &TEST_API_METHOD
|
||||
}
|
||||
|
||||
static API_ROOT: MethodInfo = MethodInfo {
|
||||
get: Some(&TEST_API_METHOD),
|
||||
subdirs: Some(&subdirmap!{
|
||||
methodinfo!{
|
||||
API_ROOT,
|
||||
get => &TEST_API_METHOD,
|
||||
subdirs => &subdirmap!{
|
||||
test => &API3_TEST,
|
||||
nodes => &API3_NODES
|
||||
}),
|
||||
..METHOD_INFO_DEFAULTS
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! http_error {
|
||||
($status:ident, $msg:expr) => {{
|
||||
|
|
Loading…
Reference in New Issue