Run rustfmt.

This commit is contained in:
Jimmy Cuadra 2017-07-07 23:24:37 -07:00
parent 60e4d9a86c
commit 3b059d1735
2 changed files with 42 additions and 16 deletions

View File

@ -10,9 +10,13 @@ pub mod unversioned {
use {Client, Error}; use {Client, Error};
/// Make a request to this API endpoint. /// Make a request to this API endpoint.
pub fn call<'a, C>(client: &'a Client<C>, request: Request) pub fn call<'a, C>(
-> impl Future<Item = Response, Error = Error> + 'a client: &'a Client<C>,
where C: Connect { request: Request,
) -> impl Future<Item = Response, Error = Error> + 'a
where
C: Connect,
{
client.request::<Endpoint>(request) client.request::<Endpoint>(request)
} }
} }

View File

@ -6,8 +6,10 @@
extern crate futures; extern crate futures;
extern crate hyper; extern crate hyper;
#[cfg(feature = "tls")] extern crate hyper_tls; #[cfg(feature = "tls")]
#[cfg(feature = "tls")] extern crate native_tls; extern crate hyper_tls;
#[cfg(feature = "tls")]
extern crate native_tls;
extern crate ruma_api; extern crate ruma_api;
extern crate ruma_client_api; extern crate ruma_client_api;
extern crate ruma_identifiers; extern crate ruma_identifiers;
@ -21,10 +23,12 @@ use std::convert::TryInto;
use std::rc::Rc; use std::rc::Rc;
use futures::future::{Future, FutureFrom, IntoFuture}; use futures::future::{Future, FutureFrom, IntoFuture};
use hyper::{Client as HyperClient}; use hyper::Client as HyperClient;
use hyper::client::{Connect, HttpConnector}; use hyper::client::{Connect, HttpConnector};
#[cfg(feature = "hyper-tls")] use hyper_tls::HttpsConnector; #[cfg(feature = "hyper-tls")]
#[cfg(feature = "hyper-tls")] use native_tls::Error as NativeTlsError; use hyper_tls::HttpsConnector;
#[cfg(feature = "hyper-tls")]
use native_tls::Error as NativeTlsError;
use ruma_api::Endpoint; use ruma_api::Endpoint;
use tokio_core::reactor::Handle; use tokio_core::reactor::Handle;
use url::Url; use url::Url;
@ -39,7 +43,10 @@ mod session;
/// A client for the Matrix client-server API. /// A client for the Matrix client-server API.
#[derive(Debug)] #[derive(Debug)]
pub struct Client<C> where C: Connect { pub struct Client<C>
where
C: Connect,
{
homeserver_url: Url, homeserver_url: Url,
hyper: Rc<HyperClient<C>>, hyper: Rc<HyperClient<C>>,
session: Option<Session>, session: Option<Session>,
@ -64,13 +71,21 @@ impl Client<HttpsConnector<HttpConnector>> {
Ok(Client { Ok(Client {
homeserver_url, homeserver_url,
hyper: Rc::new(HyperClient::configure().connector(connector).keep_alive(true).build(handle)), hyper: Rc::new(
HyperClient::configure()
.connector(connector)
.keep_alive(true)
.build(handle),
),
session: None, session: None,
}) })
} }
} }
impl<C> Client<C> where C: Connect { impl<C> Client<C>
where
C: Connect,
{
/// Creates a new client using the given `hyper::Client`. /// Creates a new client using the given `hyper::Client`.
/// ///
/// This allows the user to configure the details of HTTP as desired. /// This allows the user to configure the details of HTTP as desired.
@ -83,16 +98,23 @@ impl<C> Client<C> where C: Connect {
} }
/// Makes a request to a Matrix API endpoint. /// Makes a request to a Matrix API endpoint.
pub(crate) fn request<'a, E>(&'a self, request: <E as Endpoint>::Request) pub(crate) fn request<'a, E>(
-> impl Future<Item = E::Response, Error = Error> + 'a &'a self,
where E: Endpoint, request: <E as Endpoint>::Request,
<E as Endpoint>::Response: 'a { ) -> impl Future<Item = E::Response, Error = Error> + 'a
where
E: Endpoint,
<E as Endpoint>::Response: 'a,
{
request request
.try_into() .try_into()
.map_err(Error::from) .map_err(Error::from)
.into_future() .into_future()
.and_then(move |hyper_request| { .and_then(move |hyper_request| {
self.hyper.clone().request(hyper_request).map_err(Error::from) self.hyper
.clone()
.request(hyper_request)
.map_err(Error::from)
}) })
.and_then(|hyper_response| { .and_then(|hyper_response| {
E::Response::future_from(hyper_response).map_err(Error::from) E::Response::future_from(hyper_response).map_err(Error::from)