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