All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rust.hyper.api_mod.mustache Maven / Gradle / Ivy

use hyper;
use serde;
use serde_json;

#[derive(Debug)]
pub enum Error {
    UriError(hyper::error::UriError),
    Hyper(hyper::Error),
    Serde(serde_json::Error),
    ApiError(ApiError),
}

#[derive(Debug)]
pub struct ApiError {
    pub code: hyper::StatusCode,
    pub content: Option,
}

impl<'de, T> From<(hyper::StatusCode, &'de [u8])> for Error 
    where T: serde::Deserialize<'de> {
    fn from(e: (hyper::StatusCode, &'de [u8])) -> Self {
        if e.1.len() == 0 {
            return Error::ApiError(ApiError{
                code: e.0,
                content: None,
            });
        }
        match serde_json::from_slice::(e.1) {
            Ok(t) => Error::ApiError(ApiError{
                code: e.0,
                content: Some(t),
            }),
            Err(e) => {
                Error::from(e)
            }
        }
    }
}

impl From for Error {
    fn from(e: hyper::Error) -> Self {
        return Error::Hyper(e)
    }
}

impl From for Error {
    fn from(e: serde_json::Error) -> Self {
        return Error::Serde(e)
    }
}

mod request;

{{#apiInfo}}
{{#apis}}
mod {{{classFilename}}};
{{#operations}}
{{#operation}}
{{#-last}}
pub use self::{{{classFilename}}}::{ {{{classname}}}, {{{classname}}}Client };
{{/-last}}
{{/operation}}
{{/operations}}
{{/apis}}
{{/apiInfo}}

pub mod configuration;
pub mod client;




© 2015 - 2024 Weber Informatics LLC | Privacy Policy