From 169b6cb9f9a9689cc29adebea09e54fc8e1dc161 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 18 Jul 2019 23:22:53 +0200 Subject: [PATCH] Remove futures and hyper dependencies --- Cargo.toml | 2 -- src/lib.rs | 47 +++++++++++++---------------------------------- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9c70d78b..dcbe4396 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,7 @@ version = "0.8.0" edition = "2018" [dependencies] -futures = "0.1.27" http = "0.1.17" -hyper = "0.12.29" serde_json = "1.0.39" serde_urlencoded = "0.5.5" ruma-identifiers = "0.13.0" diff --git a/src/lib.rs b/src/lib.rs index 6ba07852..819752ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,25 +35,26 @@ )] use std::{ - convert::TryInto, + convert::{TryFrom, TryInto}, error::Error as StdError, fmt::{Display, Formatter, Result as FmtResult}, io, }; -use futures::future::FutureFrom; use http::{self, Method, Request, Response, StatusCode}; -use hyper::{self, Body}; use ruma_identifiers; use serde_json; use serde_urlencoded; /// A Matrix API endpoint. -pub trait Endpoint { +pub trait Endpoint { /// Data needed to make a request to the endpoint. - type Request: TryInto, Error = Error> + FutureFrom, Error = Error>; + type Request: TryFrom>, Error = Error> + + TryInto>, Error = Error>; + /// Data returned from the endpoint. - type Response: FutureFrom, Error = Error> + TryInto>; + type Response: TryFrom>, Error = Error> + + TryInto>, Error = Error>; /// Metadata about the endpoint. const METADATA: Metadata; @@ -68,7 +69,6 @@ impl Display for Error { fn fmt(&self, f: &mut Formatter) -> FmtResult { let message = match self.0 { InnerError::Http(_) => "An error converting to or from `http` types occurred.".into(), - InnerError::Hyper(_) => "A Hyper error occurred.".into(), InnerError::Io(_) => "An I/O error occurred.".into(), InnerError::SerdeJson(_) => "A JSON error occurred.".into(), InnerError::SerdeUrlEncodedDe(_) => { @@ -92,8 +92,6 @@ impl StdError for Error {} pub(crate) enum InnerError { /// An HTTP error. Http(http::Error), - /// An Hyper error. - Hyper(hyper::Error), /// A I/O error. Io(io::Error), /// A Serde JSON error. @@ -114,12 +112,6 @@ impl From for Error { } } -impl From for Error { - fn from(error: hyper::Error) -> Self { - Self(InnerError::Hyper(error)) - } -} - impl From for Error { fn from(error: io::Error) -> Self { Self(InnerError::Io(error)) @@ -180,7 +172,6 @@ mod tests { pub mod create { use std::convert::TryFrom; - use futures::future::{err, ok, FutureFrom, FutureResult}; use http::{ header::CONTENT_TYPE, method::Method, Request as HttpRequest, Response as HttpResponse, }; @@ -189,12 +180,12 @@ mod tests { use serde_json; use url::percent_encoding; - use super::super::{Endpoint as ApiEndpoint, Error, Metadata}; + use crate::{Endpoint as ApiEndpoint, Error, Metadata}; #[derive(Debug)] pub struct Endpoint; - impl ApiEndpoint, Vec> for Endpoint { + impl ApiEndpoint for Endpoint { type Request = Request; type Response = Response; @@ -244,15 +235,6 @@ mod tests { } } - impl FutureFrom>> for Request { - type Future = FutureResult; - type Error = Error; - - fn future_from(request: HttpRequest>) -> Self::Future { - FutureResult::from(Self::try_from(request)) - } - } - impl TryFrom>> for Request { type Error = Error; @@ -276,17 +258,14 @@ mod tests { #[derive(Clone, Copy, Debug)] pub struct Response; - impl FutureFrom>> for Response { - type Future = FutureResult; + impl TryFrom>> for Response { type Error = Error; - fn future_from( - http_response: HttpResponse>, - ) -> FutureResult { + fn try_from(http_response: HttpResponse>) -> Result { if http_response.status().is_success() { - ok(Response) + Ok(Response) } else { - err(http_response.status().into()) + Err(http_response.status().into()) } } }