remove hardcoded static lifetime
This commit is contained in:
parent
89feb6acdf
commit
f1c0021436
|
@ -3,21 +3,21 @@ use failure::*;
|
||||||
use json_schema::*;
|
use json_schema::*;
|
||||||
use serde_json::{Value};
|
use serde_json::{Value};
|
||||||
|
|
||||||
pub struct ApiMethod {
|
pub struct ApiMethod<'a> {
|
||||||
pub description: &'static str,
|
pub description: &'a str,
|
||||||
pub properties: &'static StaticPropertyMap,
|
pub properties: &'a PropertyMap<'a>,
|
||||||
pub returns: &'static Jss,
|
pub returns: &'a Jss<'a>,
|
||||||
pub handler: fn(Value) -> Result<Value, Error>,
|
pub handler: fn(Value) -> Result<Value, Error>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type StaticSubdirMap = crate::static_map::StaticMap<'static, &'static str, &'static MethodInfo>;
|
pub type SubdirMap<'a> = crate::static_map::StaticMap<'a, &'a str, &'a MethodInfo<'a>>;
|
||||||
|
|
||||||
pub struct MethodInfo {
|
pub struct MethodInfo<'a> {
|
||||||
pub get: Option<&'static ApiMethod>,
|
pub get: Option<&'a ApiMethod<'a>>,
|
||||||
pub put: Option<&'static ApiMethod>,
|
pub put: Option<&'a ApiMethod<'a>>,
|
||||||
pub post: Option<&'static ApiMethod>,
|
pub post: Option<&'a ApiMethod<'a>>,
|
||||||
pub delete: Option<&'static ApiMethod>,
|
pub delete: Option<&'a ApiMethod<'a>>,
|
||||||
pub subdirs: Option<&'static StaticSubdirMap>,
|
pub subdirs: Option<&'a SubdirMap<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static METHOD_INFO_DEFAULTS: MethodInfo = MethodInfo {
|
pub static METHOD_INFO_DEFAULTS: MethodInfo = MethodInfo {
|
||||||
|
@ -28,7 +28,7 @@ pub static METHOD_INFO_DEFAULTS: MethodInfo = MethodInfo {
|
||||||
subdirs: None,
|
subdirs: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn find_method_info<'a>(root: &'a MethodInfo, components: &[&str]) -> Option<&'a MethodInfo> {
|
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); };
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
use static_map::StaticMap;
|
use static_map::StaticMap;
|
||||||
|
|
||||||
pub type StaticPropertyMap = StaticMap<'static, &'static str, Jss>;
|
pub type PropertyMap<'a> = StaticMap<'a, &'a str, Jss<'a>>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct JssBoolean {
|
pub struct JssBoolean<'a> {
|
||||||
pub description: &'static str,
|
pub description: &'a str,
|
||||||
pub optional: Option<bool>,
|
pub optional: Option<bool>,
|
||||||
pub default: Option<bool>,
|
pub default: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct JssInteger {
|
pub struct JssInteger<'a> {
|
||||||
pub description: &'static str,
|
pub description: &'a str,
|
||||||
pub optional: Option<bool>,
|
pub optional: Option<bool>,
|
||||||
pub minimum: Option<usize>,
|
pub minimum: Option<usize>,
|
||||||
pub maximum: Option<usize>,
|
pub maximum: Option<usize>,
|
||||||
|
@ -19,38 +19,38 @@ pub struct JssInteger {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct JssString {
|
pub struct JssString<'a> {
|
||||||
pub description: &'static str,
|
pub description: &'a str,
|
||||||
pub optional: Option<bool>,
|
pub optional: Option<bool>,
|
||||||
pub default: Option<&'static str>,
|
pub default: Option<&'a str>,
|
||||||
pub min_length: Option<usize>,
|
pub min_length: Option<usize>,
|
||||||
pub max_length: Option<usize>,
|
pub max_length: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct JssArray {
|
pub struct JssArray<'a> {
|
||||||
pub description: &'static str,
|
pub description: &'a str,
|
||||||
pub optional: Option<bool>,
|
pub optional: Option<bool>,
|
||||||
pub items: &'static Jss,
|
pub items: &'a Jss<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct JssObject {
|
pub struct JssObject<'a> {
|
||||||
pub description: &'static str,
|
pub description: &'a str,
|
||||||
pub optional: Option<bool>,
|
pub optional: Option<bool>,
|
||||||
pub additional_properties: Option<bool>,
|
pub additional_properties: Option<bool>,
|
||||||
pub properties: &'static StaticPropertyMap,
|
pub properties: &'a PropertyMap<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Jss {
|
pub enum Jss<'a> {
|
||||||
Null,
|
Null,
|
||||||
Boolean(JssBoolean),
|
Boolean(JssBoolean<'a>),
|
||||||
Integer(JssInteger),
|
Integer(JssInteger<'a>),
|
||||||
String(JssString),
|
String(JssString<'a>),
|
||||||
Object(JssObject),
|
Object(JssObject<'a>),
|
||||||
Array(JssArray),
|
Array(JssArray<'a>),
|
||||||
Reference { reference: &'static Jss },
|
Reference { reference: &'a Jss<'a> },
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static DEFAULTBOOL: JssBoolean = JssBoolean {
|
pub static DEFAULTBOOL: JssBoolean = JssBoolean {
|
||||||
|
@ -109,7 +109,7 @@ macro_rules! Array {
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static EMPTYOBJECT: StaticPropertyMap = StaticPropertyMap { entries: &[] };
|
pub static EMPTYOBJECT: PropertyMap = PropertyMap { entries: &[] };
|
||||||
|
|
||||||
pub static DEFAULTOBJECT: JssObject = JssObject {
|
pub static DEFAULTOBJECT: JssObject = JssObject {
|
||||||
description: "",
|
description: "",
|
||||||
|
|
|
@ -28,7 +28,7 @@ use hyper::{Method, Body, Request, Response, Server, StatusCode};
|
||||||
use hyper::rt::Future;
|
use hyper::rt::Future;
|
||||||
use hyper::service::service_fn_ok;
|
use hyper::service::service_fn_ok;
|
||||||
|
|
||||||
static PARAMETERS1: StaticPropertyMap = StaticPropertyMap {
|
static PARAMETERS1: PropertyMap = PropertyMap {
|
||||||
entries: &[
|
entries: &[
|
||||||
("force", Boolean!{
|
("force", Boolean!{
|
||||||
description => "Test for boolean options."
|
description => "Test for boolean options."
|
||||||
|
@ -54,7 +54,7 @@ static PARAMETERS1: StaticPropertyMap = StaticPropertyMap {
|
||||||
})),
|
})),
|
||||||
("myobject", Object!{
|
("myobject", Object!{
|
||||||
description => "TEST Object.",
|
description => "TEST Object.",
|
||||||
properties => &StaticPropertyMap {
|
properties => &PropertyMap {
|
||||||
entries: &[
|
entries: &[
|
||||||
("vmid", Jss::Reference { reference: &PVE_VMID}),
|
("vmid", Jss::Reference { reference: &PVE_VMID}),
|
||||||
("loop", Integer!{
|
("loop", Integer!{
|
||||||
|
@ -97,7 +97,7 @@ fn test_api_handler(param: Value) -> Result<Value, Error> {
|
||||||
|
|
||||||
static TEST_API_METHOD: ApiMethod = ApiMethod {
|
static TEST_API_METHOD: ApiMethod = ApiMethod {
|
||||||
description: "This is a simple test.",
|
description: "This is a simple test.",
|
||||||
properties: &StaticPropertyMap {
|
properties: &PropertyMap {
|
||||||
entries: &[
|
entries: &[
|
||||||
("force", Boolean!{
|
("force", Boolean!{
|
||||||
optional => Some(true),
|
optional => Some(true),
|
||||||
|
@ -117,7 +117,7 @@ static API3_NODES: MethodInfo = MethodInfo {
|
||||||
|
|
||||||
static API_ROOT: MethodInfo = MethodInfo {
|
static API_ROOT: MethodInfo = MethodInfo {
|
||||||
get: Some(&TEST_API_METHOD),
|
get: Some(&TEST_API_METHOD),
|
||||||
subdirs: Some(&StaticSubdirMap {
|
subdirs: Some(&SubdirMap {
|
||||||
entries: &[
|
entries: &[
|
||||||
("nodes", &API3_NODES),
|
("nodes", &API3_NODES),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue