From e72677bf5077b2ddb545395feca0e7db7cb353bc Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 7 Nov 2018 11:06:37 +0100 Subject: [PATCH] pass ApiMethod to handler --- src/api3.rs | 2 +- src/api_info.rs | 4 +--- src/main.rs | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/api3.rs b/src/api3.rs index 9dbb5938..bf496f13 100644 --- a/src/api3.rs +++ b/src/api3.rs @@ -7,7 +7,7 @@ use crate::api_info::*; use serde_json::{json, Value}; -fn test_api_handler(param: Value) -> Result { +fn test_api_handler(param: Value, info: &ApiMethod) -> Result { println!("This is a test {}", param); // let force: Option = Some(false); diff --git a/src/api_info.rs b/src/api_info.rs index ab2a92d8..fb314d64 100644 --- a/src/api_info.rs +++ b/src/api_info.rs @@ -5,15 +5,13 @@ use serde_json::{Value}; use std::collections::HashMap; -#[derive(Debug)] pub struct ApiMethod { pub description: &'static str, pub parameters: Jss, pub returns: Jss, - pub handler: fn(Value) -> Result, + pub handler: fn(Value, &ApiMethod) -> Result, } -#[derive(Debug)] pub struct MethodInfo { pub get: Option, pub put: Option, diff --git a/src/main.rs b/src/main.rs index 1265119b..9aed6d19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,7 +78,7 @@ fn handle_request(req: Request) -> Response { None => json!({}), }; - match (api_method.handler)(param) { + match (api_method.handler)(param, &api_method) { Ok(res) => { let json_str = res.to_string(); return Response::new(Body::from(json_str));