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)]
|
#[derive(Debug)]
|
||||||
pub struct MethodInfo<'a> {
|
pub struct MethodInfo<'a> {
|
||||||
pub get: Option<&'a ApiMethod<'a>>,
|
pub get: Option<&'a ApiMethod<'a>>,
|
||||||
|
@ -40,6 +41,16 @@ pub static METHOD_INFO_DEFAULTS: MethodInfo = MethodInfo {
|
||||||
subdirs: None,
|
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>> {
|
pub fn find_method_info<'a>(root: &'a MethodInfo, components: &[&str]) -> Option<&'a MethodInfo<'a>> {
|
||||||
|
|
||||||
if components.len() == 0 { return Some(root); };
|
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 {
|
methodinfo!{
|
||||||
..METHOD_INFO_DEFAULTS
|
API3_TEST,
|
||||||
};
|
}
|
||||||
|
|
||||||
static API3_NODES: MethodInfo = MethodInfo {
|
methodinfo!{
|
||||||
get: Some(&TEST_API_METHOD),
|
API3_NODES,
|
||||||
..METHOD_INFO_DEFAULTS
|
get => &TEST_API_METHOD
|
||||||
};
|
}
|
||||||
|
|
||||||
static API_ROOT: MethodInfo = MethodInfo {
|
methodinfo!{
|
||||||
get: Some(&TEST_API_METHOD),
|
API_ROOT,
|
||||||
subdirs: Some(&subdirmap!{
|
get => &TEST_API_METHOD,
|
||||||
|
subdirs => &subdirmap!{
|
||||||
test => &API3_TEST,
|
test => &API3_TEST,
|
||||||
nodes => &API3_NODES
|
nodes => &API3_NODES
|
||||||
}),
|
}
|
||||||
..METHOD_INFO_DEFAULTS
|
}
|
||||||
};
|
|
||||||
|
|
||||||
macro_rules! http_error {
|
macro_rules! http_error {
|
||||||
($status:ident, $msg:expr) => {{
|
($status:ident, $msg:expr) => {{
|
||||||
|
|
Loading…
Reference in New Issue