From c38d18484d89f3b4b11fc87fe5ca8449fbcaaefb Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 21 Nov 2019 13:43:10 +0100 Subject: [PATCH] api: move ApiMethod from router to top level Signed-off-by: Wolfgang Bumiller --- proxmox-api/src/lib.rs | 29 ++++++++++++++++++++++++++++- proxmox-api/src/router.rs | 29 +---------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/proxmox-api/src/lib.rs b/proxmox-api/src/lib.rs index 73fd9ec3..eab25fec 100644 --- a/proxmox-api/src/lib.rs +++ b/proxmox-api/src/lib.rs @@ -1,5 +1,6 @@ //! Proxmox API module. This provides utilities for HTTP and command line APIs. +use std::fmt; use std::future::Future; use failure::Error; @@ -16,7 +17,7 @@ pub mod schema; pub use rpc_environment::{RpcEnvironment, RpcEnvironmentType}; #[doc(inline)] -pub use router::ApiMethod; +pub use router::Router; #[doc(inline)] pub use error::HttpError; @@ -46,3 +47,29 @@ pub enum ApiHandler { Sync(ApiHandlerFn), Async(ApiAsyncHandlerFn), } + +/// This struct defines synchronous API call which returns the restulkt as json `Value` +pub struct ApiMethod { + /// The protected flag indicates that the provides function should be forwarded + /// to the deaemon running in priviledged mode. + pub protected: bool, + /// This flag indicates that the provided method may change the local timezone, so the server + /// should do a tzset afterwards + pub reload_timezone: bool, + /// Parameter type Schema + pub parameters: &'static schema::ObjectSchema, + /// Return type Schema + pub returns: &'static schema::Schema, + /// Handler function + pub handler: &'static ApiHandler, +} + +impl std::fmt::Debug for ApiMethod { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "ApiMethod {{ ")?; + write!(f, " parameters: {:?}", self.parameters)?; + write!(f, " returns: {:?}", self.returns)?; + write!(f, " handler: {:p}", &self.handler)?; + write!(f, "}}") + } +} diff --git a/proxmox-api/src/router.rs b/proxmox-api/src/router.rs index 8d1c25b5..c870cd97 100644 --- a/proxmox-api/src/router.rs +++ b/proxmox-api/src/router.rs @@ -1,38 +1,11 @@ use std::collections::HashMap; -use std::fmt; use failure::Error; use hyper::Method; use serde_json::Value; use crate::schema::{ObjectSchema, Schema}; -use crate::{ApiHandler, RpcEnvironment}; - -/// This struct defines synchronous API call which returns the restulkt as json `Value` -pub struct ApiMethod { - /// The protected flag indicates that the provides function should be forwarded - /// to the deaemon running in priviledged mode. - pub protected: bool, - /// This flag indicates that the provided method may change the local timezone, so the server - /// should do a tzset afterwards - pub reload_timezone: bool, - /// Parameter type Schema - pub parameters: &'static ObjectSchema, - /// Return type Schema - pub returns: &'static Schema, - /// Handler function - pub handler: &'static ApiHandler, -} - -impl std::fmt::Debug for ApiMethod { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "ApiMethod {{ ")?; - write!(f, " parameters: {:?}", self.parameters)?; - write!(f, " returns: {:?}", self.returns)?; - write!(f, " handler: {:p}", &self.handler)?; - write!(f, "}}") - } -} +use crate::{ApiHandler, ApiMethod, RpcEnvironment}; const NULL_SCHEMA: Schema = Schema::Null;