Remove futures and hyper dependencies

This commit is contained in:
Jonas Platte 2019-07-18 23:22:53 +02:00
parent b0c1997016
commit 169b6cb9f9
2 changed files with 13 additions and 36 deletions

View File

@ -13,9 +13,7 @@ version = "0.8.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
futures = "0.1.27"
http = "0.1.17" http = "0.1.17"
hyper = "0.12.29"
serde_json = "1.0.39" serde_json = "1.0.39"
serde_urlencoded = "0.5.5" serde_urlencoded = "0.5.5"
ruma-identifiers = "0.13.0" ruma-identifiers = "0.13.0"

View File

@ -35,25 +35,26 @@
)] )]
use std::{ use std::{
convert::TryInto, convert::{TryFrom, TryInto},
error::Error as StdError, error::Error as StdError,
fmt::{Display, Formatter, Result as FmtResult}, fmt::{Display, Formatter, Result as FmtResult},
io, io,
}; };
use futures::future::FutureFrom;
use http::{self, Method, Request, Response, StatusCode}; use http::{self, Method, Request, Response, StatusCode};
use hyper::{self, Body};
use ruma_identifiers; use ruma_identifiers;
use serde_json; use serde_json;
use serde_urlencoded; use serde_urlencoded;
/// A Matrix API endpoint. /// A Matrix API endpoint.
pub trait Endpoint<T = Body, U = Body> { pub trait Endpoint {
/// Data needed to make a request to the endpoint. /// Data needed to make a request to the endpoint.
type Request: TryInto<Request<T>, Error = Error> + FutureFrom<Request<T>, Error = Error>; type Request: TryFrom<Request<Vec<u8>>, Error = Error>
+ TryInto<Request<Vec<u8>>, Error = Error>;
/// Data returned from the endpoint. /// Data returned from the endpoint.
type Response: FutureFrom<Response<U>, Error = Error> + TryInto<Response<U>>; type Response: TryFrom<Response<Vec<u8>>, Error = Error>
+ TryInto<Response<Vec<u8>>, Error = Error>;
/// Metadata about the endpoint. /// Metadata about the endpoint.
const METADATA: Metadata; const METADATA: Metadata;
@ -68,7 +69,6 @@ impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> FmtResult { fn fmt(&self, f: &mut Formatter) -> FmtResult {
let message = match self.0 { let message = match self.0 {
InnerError::Http(_) => "An error converting to or from `http` types occurred.".into(), 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::Io(_) => "An I/O error occurred.".into(),
InnerError::SerdeJson(_) => "A JSON error occurred.".into(), InnerError::SerdeJson(_) => "A JSON error occurred.".into(),
InnerError::SerdeUrlEncodedDe(_) => { InnerError::SerdeUrlEncodedDe(_) => {
@ -92,8 +92,6 @@ impl StdError for Error {}
pub(crate) enum InnerError { pub(crate) enum InnerError {
/// An HTTP error. /// An HTTP error.
Http(http::Error), Http(http::Error),
/// An Hyper error.
Hyper(hyper::Error),
/// A I/O error. /// A I/O error.
Io(io::Error), Io(io::Error),
/// A Serde JSON error. /// A Serde JSON error.
@ -114,12 +112,6 @@ impl From<http::Error> for Error {
} }
} }
impl From<hyper::Error> for Error {
fn from(error: hyper::Error) -> Self {
Self(InnerError::Hyper(error))
}
}
impl From<io::Error> for Error { impl From<io::Error> for Error {
fn from(error: io::Error) -> Self { fn from(error: io::Error) -> Self {
Self(InnerError::Io(error)) Self(InnerError::Io(error))
@ -180,7 +172,6 @@ mod tests {
pub mod create { pub mod create {
use std::convert::TryFrom; use std::convert::TryFrom;
use futures::future::{err, ok, FutureFrom, FutureResult};
use http::{ use http::{
header::CONTENT_TYPE, method::Method, Request as HttpRequest, Response as HttpResponse, header::CONTENT_TYPE, method::Method, Request as HttpRequest, Response as HttpResponse,
}; };
@ -189,12 +180,12 @@ mod tests {
use serde_json; use serde_json;
use url::percent_encoding; use url::percent_encoding;
use super::super::{Endpoint as ApiEndpoint, Error, Metadata}; use crate::{Endpoint as ApiEndpoint, Error, Metadata};
#[derive(Debug)] #[derive(Debug)]
pub struct Endpoint; pub struct Endpoint;
impl ApiEndpoint<Vec<u8>, Vec<u8>> for Endpoint { impl ApiEndpoint for Endpoint {
type Request = Request; type Request = Request;
type Response = Response; type Response = Response;
@ -244,15 +235,6 @@ mod tests {
} }
} }
impl FutureFrom<HttpRequest<Vec<u8>>> for Request {
type Future = FutureResult<Self, Self::Error>;
type Error = Error;
fn future_from(request: HttpRequest<Vec<u8>>) -> Self::Future {
FutureResult::from(Self::try_from(request))
}
}
impl TryFrom<HttpRequest<Vec<u8>>> for Request { impl TryFrom<HttpRequest<Vec<u8>>> for Request {
type Error = Error; type Error = Error;
@ -276,17 +258,14 @@ mod tests {
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct Response; pub struct Response;
impl FutureFrom<HttpResponse<Vec<u8>>> for Response { impl TryFrom<HttpResponse<Vec<u8>>> for Response {
type Future = FutureResult<Self, Self::Error>;
type Error = Error; type Error = Error;
fn future_from( fn try_from(http_response: HttpResponse<Vec<u8>>) -> Result<Response, Self::Error> {
http_response: HttpResponse<Vec<u8>>,
) -> FutureResult<Self, Self::Error> {
if http_response.status().is_success() { if http_response.status().is_success() {
ok(Response) Ok(Response)
} else { } else {
err(http_response.status().into()) Err(http_response.status().into())
} }
} }
} }