]> git.proxmox.com Git - proxmox-backup.git/blob - src/api_info.rs
remove hardcoded static lifetime
[proxmox-backup.git] / src / api_info.rs
1 use failure::*;
2
3 use json_schema::*;
4 use serde_json::{Value};
5
6 pub struct ApiMethod<'a> {
7 pub description: &'a str,
8 pub properties: &'a PropertyMap<'a>,
9 pub returns: &'a Jss<'a>,
10 pub handler: fn(Value) -> Result<Value, Error>,
11 }
12
13 pub type SubdirMap<'a> = crate::static_map::StaticMap<'a, &'a str, &'a MethodInfo<'a>>;
14
15 pub struct MethodInfo<'a> {
16 pub get: Option<&'a ApiMethod<'a>>,
17 pub put: Option<&'a ApiMethod<'a>>,
18 pub post: Option<&'a ApiMethod<'a>>,
19 pub delete: Option<&'a ApiMethod<'a>>,
20 pub subdirs: Option<&'a SubdirMap<'a>>,
21 }
22
23 pub static METHOD_INFO_DEFAULTS: MethodInfo = MethodInfo {
24 get: None,
25 put: None,
26 post: None,
27 delete: None,
28 subdirs: None,
29 };
30
31 pub fn find_method_info<'a>(root: &'a MethodInfo, components: &[&str]) -> Option<&'a MethodInfo<'a>> {
32
33 if components.len() == 0 { return Some(root); };
34
35 let (dir, rest) = (components[0], &components[1..]);
36
37 if let Some(ref dirmap) = root.subdirs {
38 if let Some(info) = dirmap.get(&dir) {
39 return find_method_info(info, rest);
40 }
41 }
42
43 None
44 }