diff --git a/examples/async.rs b/examples/async.rs index d35c31a..b372246 100644 --- a/examples/async.rs +++ b/examples/async.rs @@ -7,7 +7,7 @@ extern crate tokio; use std::mem; use std::io::{self, Cursor}; use futures::{Future, Stream}; -use reqwest::async::{Client, Decoder}; +use reqwest::r#async::{Client, Decoder}; fn fetch() -> impl Future { diff --git a/examples/async_multiple_requests.rs b/examples/async_multiple_requests.rs index 5644f34..f52f499 100644 --- a/examples/async_multiple_requests.rs +++ b/examples/async_multiple_requests.rs @@ -7,7 +7,7 @@ extern crate serde; extern crate serde_json; use futures::Future; -use reqwest::async::{Client, Response}; +use reqwest::r#async::{Client, Response}; use serde::Deserialize; #[derive(Deserialize, Debug)] diff --git a/examples/async_stream.rs b/examples/async_stream.rs index f233cb5..dbaf30a 100644 --- a/examples/async_stream.rs +++ b/examples/async_stream.rs @@ -13,7 +13,7 @@ use std::path::Path; use bytes::Bytes; use futures::{Async, Future, Poll, Stream}; -use reqwest::async::{Client, Decoder}; +use reqwest::r#async::{Client, Decoder}; use tokio::fs::File; use tokio::io::AsyncRead; diff --git a/src/async_impl/body.rs b/src/async_impl/body.rs index 42119a1..012e29a 100644 --- a/src/async_impl/body.rs +++ b/src/async_impl/body.rs @@ -72,7 +72,7 @@ impl Body { impl Stream for Body { type Item = Chunk; - type Error = ::Error; + type Error = crate::Error; #[inline] fn poll(&mut self) -> Poll, Self::Error> { @@ -80,10 +80,10 @@ impl Stream for Body { Inner::Hyper { ref mut body, ref mut timeout } => { if let Some(ref mut timeout) = timeout { if let Async::Ready(()) = try_!(timeout.poll()) { - return Err(::error::timedout(None)); + return Err(crate::error::timedout(None)); } } - try_ready!(body.poll_data().map_err(::error::from)) + try_ready!(body.poll_data().map_err(crate::error::from)) }, Inner::Reusable(ref mut bytes) => { return if bytes.is_empty() { diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index c69588f..b04f795 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -5,7 +5,7 @@ use std::net::IpAddr; use bytes::Bytes; use futures::{Async, Future, Poll}; -use header::{ +use crate::header::{ Entry, HeaderMap, HeaderValue, @@ -31,16 +31,16 @@ use tokio::{clock, timer::Delay}; use super::request::{Request, RequestBuilder}; use super::response::Response; -use connect::Connector; -use into_url::{expect_uri, try_uri}; -use cookie; -use redirect::{self, RedirectPolicy, remove_sensitive_headers}; -use {IntoUrl, Method, Proxy, StatusCode, Url}; -use ::proxy::get_proxies; +use crate::connect::Connector; +use crate::into_url::{expect_uri, try_uri}; +use crate::cookie; +use crate::redirect::{self, RedirectPolicy, remove_sensitive_headers}; +use crate::{IntoUrl, Method, Proxy, StatusCode, Url}; +use crate::proxy::get_proxies; #[cfg(feature = "tls")] -use {Certificate, Identity}; +use crate::{Certificate, Identity}; #[cfg(feature = "tls")] -use ::tls::TlsBackend; +use crate::tls::TlsBackend; static DEFAULT_USER_AGENT: &'static str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); @@ -133,7 +133,7 @@ impl ClientBuilder { /// /// This method fails if TLS backend cannot be initialized, or the resolver /// cannot load the system configuration. - pub fn build(self) -> ::Result { + pub fn build(self) -> crate::Result { let config = self.config; let proxies = Arc::new(config.proxies); @@ -545,7 +545,7 @@ impl Client { /// /// This method fails if there was an error while sending request, /// redirect loop was detected or redirect limit was exhausted. - pub fn execute(&self, request: Request) -> impl Future { + pub fn execute(&self, request: Request) -> impl Future { self.execute_request(request) } @@ -568,7 +568,7 @@ impl Client { // Add cookies from the cookie store. if let Some(cookie_store_wrapper) = self.inner.cookie_store.as_ref() { - if headers.get(::header::COOKIE).is_none() { + if headers.get(crate::header::COOKIE).is_none() { let cookie_store = cookie_store_wrapper.read().unwrap(); add_cookie_header(&mut headers, &cookie_store, &url); } @@ -695,7 +695,7 @@ pub(super) struct Pending { enum PendingInner { Request(PendingRequest), - Error(Option<::Error>), + Error(Option), } struct PendingRequest { @@ -713,7 +713,7 @@ struct PendingRequest { } impl Pending { - pub(super) fn new_err(err: ::Error) -> Pending { + pub(super) fn new_err(err: crate::Error) -> Pending { Pending { inner: PendingInner::Error(Some(err)), } @@ -722,7 +722,7 @@ impl Pending { impl Future for Pending { type Item = Response; - type Error = ::Error; + type Error = crate::Error; fn poll(&mut self) -> Poll { match self.inner { @@ -734,12 +734,12 @@ impl Future for Pending { impl Future for PendingRequest { type Item = Response; - type Error = ::Error; + type Error = crate::Error; fn poll(&mut self) -> Poll { if let Some(ref mut delay) = self.timeout { if let Async::Ready(()) = try_!(delay.poll(), &self.url) { - return Err(::error::timedout(Some(self.url.clone()))); + return Err(crate::error::timedout(Some(self.url.clone()))); } } @@ -850,10 +850,10 @@ impl Future for PendingRequest { debug!("redirect_policy disallowed redirection to '{}'", loc); }, redirect::Action::LoopDetected => { - return Err(::error::loop_detected(self.url.clone())); + return Err(crate::error::loop_detected(self.url.clone())); }, redirect::Action::TooManyRedirects => { - return Err(::error::too_many_redirects(self.url.clone())); + return Err(crate::error::too_many_redirects(self.url.clone())); } } } @@ -903,7 +903,7 @@ fn add_cookie_header(headers: &mut HeaderMap, cookie_store: &cookie::CookieStore .join("; "); if !header.is_empty() { headers.insert( - ::header::COOKIE, + crate::header::COOKIE, HeaderValue::from_bytes(header.as_bytes()).unwrap() ); } diff --git a/src/async_impl/decoder.rs b/src/async_impl/decoder.rs index 7aa6848..4ff75cc 100644 --- a/src/async_impl/decoder.rs +++ b/src/async_impl/decoder.rs @@ -32,7 +32,7 @@ use hyper::{HeaderMap}; use hyper::header::{CONTENT_ENCODING, CONTENT_LENGTH, TRANSFER_ENCODING}; use super::{Body, Chunk}; -use error; +use crate::error; const INIT_BUFFER_SIZE: usize = 8192; diff --git a/src/async_impl/multipart.rs b/src/async_impl/multipart.rs index fec4428..19fb15d 100644 --- a/src/async_impl/multipart.rs +++ b/src/async_impl/multipart.rs @@ -199,7 +199,7 @@ impl Part { } /// Tries to set the mime of this part. - pub fn mime_str(self, mime: &str) -> ::Result { + pub fn mime_str(self, mime: &str) -> crate::Result { Ok(self.mime(try_!(mime.parse()))) } diff --git a/src/async_impl/request.rs b/src/async_impl/request.rs index d88becd..10e6a2a 100644 --- a/src/async_impl/request.rs +++ b/src/async_impl/request.rs @@ -10,9 +10,9 @@ use super::body::{Body}; use super::client::{Client, Pending}; use super::multipart; use super::response::Response; -use header::{CONTENT_LENGTH, CONTENT_TYPE, HeaderMap, HeaderName, HeaderValue}; +use crate::header::{CONTENT_LENGTH, CONTENT_TYPE, HeaderMap, HeaderName, HeaderValue}; use http::HttpTryFrom; -use {Method, Url}; +use crate::{Method, Url}; /// A request which can be executed with `Client::execute()`. pub struct Request { @@ -25,7 +25,7 @@ pub struct Request { /// A builder to construct the properties of a `Request`. pub struct RequestBuilder { client: Client, - request: ::Result, + request: crate::Result, } impl Request { @@ -94,7 +94,7 @@ impl Request { } impl RequestBuilder { - pub(super) fn new(client: Client, request: ::Result) -> RequestBuilder { + pub(super) fn new(client: Client, request: crate::Result) -> RequestBuilder { RequestBuilder { client, request, @@ -113,10 +113,10 @@ impl RequestBuilder { Ok(key) => { match >::try_from(value) { Ok(value) => { req.headers_mut().append(key, value); } - Err(e) => error = Some(::error::from(e.into())), + Err(e) => error = Some(crate::error::from(e.into())), } }, - Err(e) => error = Some(::error::from(e.into())), + Err(e) => error = Some(crate::error::from(e.into())), }; } if let Some(err) = error { @@ -128,7 +128,7 @@ impl RequestBuilder { /// Add a set of Headers to the existing ones on this Request. /// /// The headers will be merged in to any already set. - pub fn headers(mut self, headers: ::header::HeaderMap) -> RequestBuilder { + pub fn headers(mut self, headers: crate::header::HeaderMap) -> RequestBuilder { if let Ok(ref mut req) = self.request { replace_headers(req.headers_mut(), headers); } @@ -171,7 +171,7 @@ impl RequestBuilder { None => format!("{}:", username) }; let header_value = format!("Basic {}", encode(&auth)); - self.header(::header::AUTHORIZATION, &*header_value) + self.header(crate::header::AUTHORIZATION, &*header_value) } /// Enable HTTP bearer authentication. @@ -180,7 +180,7 @@ impl RequestBuilder { T: fmt::Display, { let header_value = format!("Bearer {}", token); - self.header(::header::AUTHORIZATION, &*header_value) + self.header(crate::header::AUTHORIZATION, &*header_value) } /// Set the request body. @@ -264,7 +264,7 @@ impl RequestBuilder { let serializer = serde_urlencoded::Serializer::new(&mut pairs); if let Err(err) = query.serialize(serializer) { - error = Some(::error::from(err)); + error = Some(crate::error::from(err)); } } if let Ok(ref mut req) = self.request { @@ -290,7 +290,7 @@ impl RequestBuilder { ); *req.body_mut() = Some(body.into()); }, - Err(err) => error = Some(::error::from(err)), + Err(err) => error = Some(crate::error::from(err)), } } if let Some(err) = error { @@ -316,7 +316,7 @@ impl RequestBuilder { ); *req.body_mut() = Some(body.into()); }, - Err(err) => error = Some(::error::from(err)), + Err(err) => error = Some(crate::error::from(err)), } } if let Some(err) = error { @@ -327,7 +327,7 @@ impl RequestBuilder { /// Build a `Request`, which can be inspected, modified and executed with /// `Client::execute()`. - pub fn build(self) -> ::Result { + pub fn build(self) -> crate::Result { self.request } @@ -358,7 +358,7 @@ impl RequestBuilder { /// rt.block_on(response) /// # } /// ``` - pub fn send(self) -> impl Future { + pub fn send(self) -> impl Future { match self.request { Ok(req) => self.client.execute_request(req), Err(err) => Pending::new_err(err), diff --git a/src/async_impl/response.rs b/src/async_impl/response.rs index 0277208..c312538 100644 --- a/src/async_impl/response.rs +++ b/src/async_impl/response.rs @@ -18,7 +18,7 @@ use serde_json; use url::Url; -use cookie; +use crate::cookie; use super::Decoder; use super::body::Body; @@ -139,14 +139,14 @@ impl Response { } /// Get the response text - pub fn text(&mut self) -> impl Future { + pub fn text(&mut self) -> impl Future { self.text_with_charset("utf-8") } /// Get the response text given a specific encoding - pub fn text_with_charset(&mut self, default_encoding: &str) -> impl Future { + pub fn text_with_charset(&mut self, default_encoding: &str) -> impl Future { let body = mem::replace(&mut self.body, Decoder::empty()); - let content_type = self.headers.get(::header::CONTENT_TYPE) + let content_type = self.headers.get(crate::header::CONTENT_TYPE) .and_then(|value| { value.to_str().ok() }) @@ -170,7 +170,7 @@ impl Response { /// Try to deserialize the response body as JSON using `serde`. #[inline] - pub fn json(&mut self) -> impl Future { + pub fn json(&mut self) -> impl Future { let body = mem::replace(&mut self.body, Decoder::empty()); Json { @@ -201,9 +201,9 @@ impl Response { /// # fn main() {} /// ``` #[inline] - pub fn error_for_status(self) -> ::Result { + pub fn error_for_status(self) -> crate::Result { if self.status.is_client_error() || self.status.is_server_error() { - Err(::error::status_code(*self.url, self.status)) + Err(crate::error::status_code(*self.url, self.status)) } else { Ok(self) } @@ -231,9 +231,9 @@ impl Response { /// # fn main() {} /// ``` #[inline] - pub fn error_for_status_ref(&self) -> ::Result<&Self> { + pub fn error_for_status_ref(&self) -> crate::Result<&Self> { if self.status.is_client_error() || self.status.is_server_error() { - Err(::error::status_code(*self.url.clone(), self.status)) + Err(crate::error::status_code(*self.url.clone(), self.status)) } else { Ok(self) } @@ -278,7 +278,7 @@ struct Json { impl Future for Json { type Item = T; - type Error = ::Error; + type Error = crate::Error; fn poll(&mut self) -> Poll { let bytes = try_ready!(self.concat.poll()); let t = try_!(serde_json::from_slice(&bytes)); @@ -301,7 +301,7 @@ struct Text { impl Future for Text { type Item = String; - type Error = ::Error; + type Error = crate::Error; fn poll(&mut self) -> Poll { let bytes = try_ready!(self.concat.poll()); // a block because of borrow checker diff --git a/src/body.rs b/src/body.rs index e60faa9..511852a 100644 --- a/src/body.rs +++ b/src/body.rs @@ -6,7 +6,7 @@ use bytes::Bytes; use futures::Future; use hyper::{self}; -use {async_impl}; +use crate::{async_impl}; /// The body of a `Request`. /// @@ -218,7 +218,7 @@ pub(crate) struct Sender { impl Sender { // A `Future` that may do blocking read calls. // As a `Future`, this integrates easily with `wait::timeout`. - pub(crate) fn send(self) -> impl Future { + pub(crate) fn send(self) -> impl Future { use std::cmp; use bytes::{BufMut, BytesMut}; use futures::future; @@ -270,7 +270,7 @@ impl Sender { .take() .expect("tx only taken on error") .abort(); - return Err(::error::from(ret)); + return Err(crate::error::from(ret)); } } } @@ -281,12 +281,12 @@ impl Sender { .as_mut() .expect("tx only taken on error") .poll_ready() - .map_err(::error::from)); + .map_err(crate::error::from)); written += buf.len() as u64; let tx = tx.as_mut().expect("tx only taken on error"); if let Err(_) = tx.send_data(buf.take().freeze().into()) { - return Err(::error::timedout(None)); + return Err(crate::error::timedout(None)); } }) } diff --git a/src/client.rs b/src/client.rs index 2a4fffb..da77339 100644 --- a/src/client.rs +++ b/src/client.rs @@ -8,11 +8,11 @@ use futures::{Async, Future, Stream}; use futures::future::{self, Either}; use futures::sync::{mpsc, oneshot}; -use request::{Request, RequestBuilder}; -use response::Response; -use {async_impl, header, Method, IntoUrl, Proxy, RedirectPolicy, wait}; +use crate::request::{Request, RequestBuilder}; +use crate::response::Response; +use crate::{async_impl, header, Method, IntoUrl, Proxy, RedirectPolicy, wait}; #[cfg(feature = "tls")] -use {Certificate, Identity}; +use crate::{Certificate, Identity}; /// A `Client` to make Requests with. /// @@ -78,7 +78,7 @@ impl ClientBuilder { /// /// This method fails if TLS backend cannot be initialized, or the resolver /// cannot load the system configuration. - pub fn build(self) -> ::Result { + pub fn build(self) -> crate::Result { ClientHandle::new(self).map(|handle| Client { inner: handle, }) @@ -502,7 +502,7 @@ impl Client { /// /// This method fails if there was an error while sending request, /// redirect loop was detected or redirect limit was exhausted. - pub fn execute(&self, request: Request) -> ::Result { + pub fn execute(&self, request: Request) -> crate::Result { self.inner.execute_request(request) } } @@ -530,7 +530,7 @@ struct ClientHandle { inner: Arc } -type ThreadSender = mpsc::UnboundedSender<(async_impl::Request, oneshot::Sender<::Result>)>; +type ThreadSender = mpsc::UnboundedSender<(async_impl::Request, oneshot::Sender>)>; struct InnerClientHandle { tx: Option, @@ -545,11 +545,11 @@ impl Drop for InnerClientHandle { } impl ClientHandle { - fn new(builder: ClientBuilder) -> ::Result { + fn new(builder: ClientBuilder) -> crate::Result { let timeout = builder.timeout; let builder = builder.inner; let (tx, rx) = mpsc::unbounded(); - let (spawn_tx, spawn_rx) = oneshot::channel::<::Result<()>>(); + let (spawn_tx, spawn_rx) = oneshot::channel::>(); let handle = try_!(thread::Builder::new().name("reqwest-internal-sync-runtime".into()).spawn(move || { use tokio::runtime::current_thread::Runtime; @@ -573,7 +573,7 @@ impl ClientHandle { }; let work = rx.for_each(move |(req, tx)| { - let mut tx_opt: Option>> = Some(tx); + let mut tx_opt: Option>> = Some(tx); let mut res_fut = client.execute(req); let task = future::poll_fn(move || { @@ -631,7 +631,7 @@ impl ClientHandle { }) } - fn execute_request(&self, req: Request) -> ::Result { + fn execute_request(&self, req: Request) -> crate::Result { let (tx, rx) = oneshot::channel(); let (req, body) = req.into_async(); let url = req.url().clone(); @@ -654,9 +654,9 @@ impl ClientHandle { let res = match wait::timeout(fut, self.timeout.0) { Ok(res) => res, - Err(wait::Waited::TimedOut) => return Err(::error::timedout(Some(url))), + Err(wait::Waited::TimedOut) => return Err(crate::error::timedout(Some(url))), Err(wait::Waited::Executor(err)) => { - return Err(::error::from(err).with_url(url)) + return Err(crate::error::from(err).with_url(url)) }, Err(wait::Waited::Inner(err)) => { return Err(err.with_url(url)); diff --git a/src/connect.rs b/src/connect.rs index e9d3c26..e6f466a 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -19,7 +19,7 @@ use std::time::Duration; #[cfg(feature = "trust-dns")] use dns::TrustDnsResolver; -use proxy::{Proxy, ProxyScheme}; +use crate::proxy::{Proxy, ProxyScheme}; #[cfg(feature = "trust-dns")] type HttpConnector = ::hyper::client::HttpConnector; @@ -70,7 +70,7 @@ impl Connector { tls: TlsConnectorBuilder, proxies: Arc>, local_addr: T, - nodelay: bool) -> ::Result + nodelay: bool) -> crate::Result where T: Into>, { @@ -204,7 +204,7 @@ fn http_connector() -> ::Result { } #[cfg(not(feature = "trust-dns"))] -fn http_connector() -> ::Result { +fn http_connector() -> crate::Result { Ok(HttpConnector::new(4)) } @@ -697,7 +697,7 @@ mod tests { use tokio::runtime::current_thread::Runtime; use self::tokio_tcp::TcpStream; use super::tunnel; - use proxy; + use crate::proxy; static TUNNEL_OK: &'static [u8] = b"\ HTTP/1.1 200 OK\r\n\ diff --git a/src/cookie.rs b/src/cookie.rs index 26f3ec3..e4b7faf 100644 --- a/src/cookie.rs +++ b/src/cookie.rs @@ -1,7 +1,7 @@ //! The cookies module contains types for working with request and response cookies. -use cookie_crate; -use header; +use crate::cookie_crate; +use crate::header; use std::borrow::Cow; use std::fmt; use std::time::SystemTime; @@ -55,7 +55,7 @@ impl Cookie<'static> { } impl<'a> Cookie<'a> { - fn parse(value: &'a ::header::HeaderValue) -> Result, CookieParseError> { + fn parse(value: &'a crate::header::HeaderValue) -> Result, CookieParseError> { std::str::from_utf8(value.as_bytes()) .map_err(cookie::ParseError::from) .and_then(cookie::Cookie::parse) diff --git a/src/error.rs b/src/error.rs index 834a525..d5c84ce 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,7 +4,7 @@ use std::io; use tokio_executor::EnterError; -use {StatusCode, Url}; +use crate::{StatusCode, Url}; /// The Errors that may occur when processing a `Request`. /// @@ -253,8 +253,8 @@ static BLOCK_IN_FUTURE: &'static str = "blocking Client used inside a Future con impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(ref url) = self.inner.url { - try!(fmt::Display::fmt(url, f)); - try!(f.write_str(": ")); + r#try!(fmt::Display::fmt(url, f)); + r#try!(f.write_str(": ")); } match self.inner.kind { Kind::Http(ref e) => fmt::Display::fmt(e, f), @@ -477,13 +477,13 @@ impl From<::rustls::TLSError> for Kind { } } -impl From<::wait::Waited> for Kind +impl From> for Kind where T: Into { - fn from(err: ::wait::Waited) -> Kind { + fn from(err: crate::wait::Waited) -> Kind { match err { - ::wait::Waited::TimedOut => io_timeout().into(), - ::wait::Waited::Executor(e) => e.into(), - ::wait::Waited::Inner(e) => e.into(), + crate::wait::Waited::TimedOut => io_timeout().into(), + crate::wait::Waited::Executor(e) => e.into(), + crate::wait::Waited::Inner(e) => e.into(), } } } @@ -558,7 +558,7 @@ macro_rules! try_ { match $e { Ok(v) => v, Err(err) => { - return Err(::error::from(err)); + return Err(crate::error::from(err)); } } ); @@ -566,7 +566,7 @@ macro_rules! try_ { match $e { Ok(v) => v, Err(err) => { - return Err(::Error::from(::error::InternalFrom(err, Some($url.clone())))); + return Err(crate::Error::from(crate::error::InternalFrom(err, Some($url.clone())))); } } ) @@ -580,7 +580,7 @@ macro_rules! try_io { return Ok(::futures::Async::NotReady); } Err(err) => { - return Err(::error::from_io(err)); + return Err(crate::error::from_io(err)); } } ) diff --git a/src/into_url.rs b/src/into_url.rs index 97502ca..db03fc9 100644 --- a/src/into_url.rs +++ b/src/into_url.rs @@ -12,28 +12,28 @@ impl IntoUrl for T {} pub trait PolyfillTryInto { // Besides parsing as a valid `Url`, the `Url` must be a valid // `http::Uri`, in that it makes sense to use in a network request. - fn into_url(self) -> ::Result; + fn into_url(self) -> crate::Result; } impl PolyfillTryInto for Url { - fn into_url(self) -> ::Result { + fn into_url(self) -> crate::Result { if self.has_host() { Ok(self) } else { - Err(::error::url_bad_scheme(self)) + Err(crate::error::url_bad_scheme(self)) } } } impl<'a> PolyfillTryInto for &'a str { - fn into_url(self) -> ::Result { + fn into_url(self) -> crate::Result { try_!(Url::parse(self)) .into_url() } } impl<'a> PolyfillTryInto for &'a String { - fn into_url(self) -> ::Result { + fn into_url(self) -> crate::Result { (&**self).into_url() } } diff --git a/src/lib.rs b/src/lib.rs index 6e1b73d..c4402f1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -267,8 +267,8 @@ mod wait; pub mod multipart; /// An 'async' implementation of the reqwest `Client`. -pub mod async { - pub use ::async_impl::{ +pub mod r#async { + pub use crate::async_impl::{ Body, Chunk, Decoder, @@ -311,7 +311,7 @@ pub mod async { /// - there was an error while sending request /// - redirect loop was detected /// - redirect limit was exhausted -pub fn get(url: T) -> ::Result { +pub fn get(url: T) -> crate::Result { Client::builder() .build()? .get(url) diff --git a/src/multipart.rs b/src/multipart.rs index 15e1595..789a9df 100644 --- a/src/multipart.rs +++ b/src/multipart.rs @@ -44,8 +44,8 @@ use std::path::Path; use mime_guess::{self, Mime}; -use async_impl::multipart::{FormParts, PartMetadata, PartProps}; -use {Body}; +use crate::async_impl::multipart::{FormParts, PartMetadata, PartProps}; +use crate::{Body}; /// A multipart/form-data request. pub struct Form { @@ -233,7 +233,7 @@ impl Part { } /// Tries to set the mime of this part. - pub fn mime_str(self, mime: &str) -> ::Result { + pub fn mime_str(self, mime: &str) -> crate::Result { Ok(self.mime(try_!(mime.parse()))) } diff --git a/src/proxy.rs b/src/proxy.rs index 2576325..dff8ff1 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -6,7 +6,7 @@ use std::net::{SocketAddr, ToSocketAddrs}; use http::{header::HeaderValue, Uri}; use hyper::client::connect::Destination; use url::percent_encoding::percent_decode; -use {IntoUrl, Url}; +use crate::{IntoUrl, Url}; use std::collections::HashMap; use std::env; #[cfg(target_os = "windows")] @@ -66,17 +66,17 @@ pub enum ProxyScheme { /// parsing from a URL-like type, whilst also supporting proxy schemes /// built directly using the factory methods. pub trait IntoProxyScheme { - fn into_proxy_scheme(self) -> ::Result; + fn into_proxy_scheme(self) -> crate::Result; } impl IntoProxyScheme for T { - fn into_proxy_scheme(self) -> ::Result { + fn into_proxy_scheme(self) -> crate::Result { ProxyScheme::parse(self.into_url()?) } } impl IntoProxyScheme for ProxyScheme { - fn into_proxy_scheme(self) -> ::Result { + fn into_proxy_scheme(self) -> crate::Result { Ok(self) } } @@ -96,7 +96,7 @@ impl Proxy { /// # } /// # fn main() {} /// ``` - pub fn http(proxy_scheme: U) -> ::Result { + pub fn http(proxy_scheme: U) -> crate::Result { Ok(Proxy::new(Intercept::Http( proxy_scheme.into_proxy_scheme()? ))) @@ -116,7 +116,7 @@ impl Proxy { /// # } /// # fn main() {} /// ``` - pub fn https(proxy_scheme: U) -> ::Result { + pub fn https(proxy_scheme: U) -> crate::Result { Ok(Proxy::new(Intercept::Https( proxy_scheme.into_proxy_scheme()? ))) @@ -136,7 +136,7 @@ impl Proxy { /// # } /// # fn main() {} /// ``` - pub fn all(proxy_scheme: U) -> ::Result { + pub fn all(proxy_scheme: U) -> crate::Result { Ok(Proxy::new(Intercept::All( proxy_scheme.into_proxy_scheme()? ))) @@ -266,10 +266,10 @@ impl ProxyScheme { // To start conservative, keep builders private for now. /// Proxy traffic via the specified URL over HTTP - fn http(url: T) -> ::Result { + fn http(url: T) -> crate::Result { Ok(ProxyScheme::Http { auth: None, - uri: ::into_url::expect_uri(&url.into_url()?), + uri: crate::into_url::expect_uri(&url.into_url()?), }) } @@ -326,7 +326,7 @@ impl ProxyScheme { /// /// Supported schemes: HTTP, HTTPS, (SOCKS5, SOCKS5H if `socks` feature is enabled). // Private for now... - fn parse(url: Url) -> ::Result { + fn parse(url: Url) -> crate::Result { // Resolve URL to a host and port #[cfg(feature = "socks")] let to_addr = || { @@ -346,7 +346,7 @@ impl ProxyScheme { "socks5" => Self::socks5(to_addr()?)?, #[cfg(feature = "socks")] "socks5h" => Self::socks5h(to_addr()?)?, - _ => return Err(::error::unknown_proxy_scheme()) + _ => return Err(crate::error::unknown_proxy_scheme()) }; if let Some(pwd) = url.password() { @@ -387,7 +387,7 @@ impl Intercept { struct Custom { // This auth only applies if the returned ProxyScheme doesn't have an auth... auth: Option, - func: Arc Option<::Result> + Send + Sync + 'static>, + func: Arc Option> + Send + Sync + 'static>, } impl Custom { diff --git a/src/redirect.rs b/src/redirect.rs index 3314be8..4978367 100644 --- a/src/redirect.rs +++ b/src/redirect.rs @@ -1,6 +1,6 @@ use std::fmt; -use header::{ +use crate::header::{ HeaderMap, AUTHORIZATION, COOKIE, @@ -10,7 +10,7 @@ use header::{ }; use hyper::StatusCode; -use Url; +use crate::Url; /// A type that controls the policy on how to handle the following of redirects. /// diff --git a/src/request.rs b/src/request.rs index 9bc5f1c..4886902 100644 --- a/src/request.rs +++ b/src/request.rs @@ -5,10 +5,10 @@ use serde::Serialize; use serde_json; use serde_urlencoded; -use body::{self, Body}; -use header::{HeaderMap, HeaderName, HeaderValue, CONTENT_TYPE}; +use crate::body::{self, Body}; +use crate::header::{HeaderMap, HeaderName, HeaderValue, CONTENT_TYPE}; use http::HttpTryFrom; -use {async_impl, Client, Method, Url}; +use crate::{async_impl, Client, Method, Url}; /// A request which can be executed with `Client::execute()`. pub struct Request { @@ -20,7 +20,7 @@ pub struct Request { #[derive(Debug)] pub struct RequestBuilder { client: Client, - request: ::Result, + request: crate::Result, } impl Request { @@ -102,7 +102,7 @@ impl Request { } pub(crate) fn into_async(self) -> (async_impl::Request, Option) { - use header::CONTENT_LENGTH; + use crate::header::CONTENT_LENGTH; let mut req_async = self.inner; let body = self.body.and_then(|body| { @@ -118,7 +118,7 @@ impl Request { } impl RequestBuilder { - pub(crate) fn new(client: Client, request: ::Result) -> RequestBuilder { + pub(crate) fn new(client: Client, request: crate::Result) -> RequestBuilder { RequestBuilder { client, request, @@ -149,10 +149,10 @@ impl RequestBuilder { Ok(key) => { match >::try_from(value) { Ok(value) => { req.headers_mut().append(key, value); } - Err(e) => error = Some(::error::from(e.into())), + Err(e) => error = Some(crate::error::from(e.into())), } }, - Err(e) => error = Some(::error::from(e.into())), + Err(e) => error = Some(crate::error::from(e.into())), }; } if let Some(err) = error { @@ -186,7 +186,7 @@ impl RequestBuilder { /// # Ok(()) /// # } /// ``` - pub fn headers(mut self, headers: ::header::HeaderMap) -> RequestBuilder { + pub fn headers(mut self, headers: crate::header::HeaderMap) -> RequestBuilder { if let Ok(ref mut req) = self.request { async_impl::request::replace_headers(req.headers_mut(), headers); } @@ -239,7 +239,7 @@ impl RequestBuilder { None => format!("{}:", username) }; let header_value = format!("Basic {}", encode(&auth)); - self.header(::header::AUTHORIZATION, &*header_value) + self.header(crate::header::AUTHORIZATION, &*header_value) } /// Enable HTTP bearer authentication. @@ -258,7 +258,7 @@ impl RequestBuilder { T: fmt::Display, { let header_value = format!("Bearer {}", token); - self.header(::header::AUTHORIZATION, &*header_value) + self.header(crate::header::AUTHORIZATION, &*header_value) } /// Set the request body. @@ -350,7 +350,7 @@ impl RequestBuilder { let serializer = serde_urlencoded::Serializer::new(&mut pairs); if let Err(err) = query.serialize(serializer) { - error = Some(::error::from(err)); + error = Some(crate::error::from(err)); } } if let Ok(ref mut req) = self.request { @@ -401,7 +401,7 @@ impl RequestBuilder { ); *req.body_mut() = Some(body.into()); }, - Err(err) => error = Some(::error::from(err)), + Err(err) => error = Some(crate::error::from(err)), } } if let Some(err) = error { @@ -446,7 +446,7 @@ impl RequestBuilder { ); *req.body_mut() = Some(body.into()); }, - Err(err) => error = Some(::error::from(err)), + Err(err) => error = Some(crate::error::from(err)), } } if let Some(err) = error { @@ -474,7 +474,7 @@ impl RequestBuilder { /// ``` /// /// See [`multipart`](multipart/) for more examples. - pub fn multipart(self, mut multipart: ::multipart::Form) -> RequestBuilder { + pub fn multipart(self, mut multipart: crate::multipart::Form) -> RequestBuilder { let mut builder = self.header( CONTENT_TYPE, format!( @@ -493,7 +493,7 @@ impl RequestBuilder { /// Build a `Request`, which can be inspected, modified and executed with /// `Client::execute()`. - pub fn build(self) -> ::Result { + pub fn build(self) -> crate::Result { self.request } @@ -503,7 +503,7 @@ impl RequestBuilder { /// /// This method fails if there was an error while sending request, /// redirect loop was detected or redirect limit was exhausted. - pub fn send(self) -> ::Result<::Response> { + pub fn send(self) -> crate::Result { self.client.execute(self.request?) } @@ -579,8 +579,8 @@ fn fmt_request_fields<'a, 'b>(f: &'a mut fmt::DebugStruct<'a, 'b>, req: &Request #[cfg(test)] mod tests { - use {body, Client, Method}; - use header::{ACCEPT, HOST, HeaderMap, HeaderValue, CONTENT_TYPE}; + use crate::{body, Client, Method}; + use crate::header::{ACCEPT, HOST, HeaderMap, HeaderValue, CONTENT_TYPE}; use std::collections::{BTreeMap, HashMap}; use serde::Serialize; use serde_json; diff --git a/src/response.rs b/src/response.rs index 8ffb43f..913a18a 100644 --- a/src/response.rs +++ b/src/response.rs @@ -8,10 +8,10 @@ use futures::{Async, Poll, Stream}; use http; use serde::de::DeserializeOwned; -use cookie; -use client::KeepCoreThreadAlive; +use crate::cookie; +use crate::client::KeepCoreThreadAlive; use hyper::header::HeaderMap; -use {async_impl, StatusCode, Url, Version, wait}; +use crate::{async_impl, StatusCode, Url, Version, wait}; /// A Response to a submitted `Request`. pub struct Response { @@ -201,11 +201,11 @@ impl Response { /// details please see [`serde_json::from_reader`]. /// [`serde_json::from_reader`]: https://docs.serde.rs/serde_json/fn.from_reader.html #[inline] - pub fn json(&mut self) -> ::Result { + pub fn json(&mut self) -> crate::Result { wait::timeout(self.inner.json(), self.timeout).map_err(|e| { match e { - wait::Waited::TimedOut => ::error::timedout(None), - wait::Waited::Executor(e) => ::error::from(e), + wait::Waited::TimedOut => crate::error::timedout(None), + wait::Waited::Executor(e) => crate::error::from(e), wait::Waited::Inner(e) => e, } }) @@ -232,7 +232,7 @@ impl Response { /// /// This consumes the body. Trying to read more, or use of `response.json()` /// will return empty values. - pub fn text(&mut self) -> ::Result { + pub fn text(&mut self) -> crate::Result { self.text_with_charset("utf-8") } @@ -259,11 +259,11 @@ impl Response { /// /// This consumes the body. Trying to read more, or use of `response.json()` /// will return empty values. - pub fn text_with_charset(&mut self, default_encoding: &str) -> ::Result { + pub fn text_with_charset(&mut self, default_encoding: &str) -> crate::Result { wait::timeout(self.inner.text_with_charset(default_encoding), self.timeout).map_err(|e| { match e { - wait::Waited::TimedOut => ::error::timedout(None), - wait::Waited::Executor(e) => ::error::from(e), + wait::Waited::TimedOut => crate::error::timedout(None), + wait::Waited::Executor(e) => crate::error::from(e), wait::Waited::Inner(e) => e, } }) @@ -290,10 +290,10 @@ impl Response { /// # } /// ``` #[inline] - pub fn copy_to(&mut self, w: &mut W) -> ::Result + pub fn copy_to(&mut self, w: &mut W) -> crate::Result where W: io::Write { - io::copy(self, w).map_err(::error::from) + io::copy(self, w).map_err(crate::error::from) } /// Turn a response into an error if the server returned an error. @@ -313,7 +313,7 @@ impl Response { /// # fn main() {} /// ``` #[inline] - pub fn error_for_status(self) -> ::Result { + pub fn error_for_status(self) -> crate::Result { let Response { body, inner, timeout, _thread_handle } = self; inner.error_for_status().map(move |inner| { Response { @@ -342,7 +342,7 @@ impl Response { /// # fn main() {} /// ``` #[inline] - pub fn error_for_status_ref(&self) -> ::Result<&Self> { + pub fn error_for_status_ref(&self) -> crate::Result<&Self> { self.inner.error_for_status_ref().and_then(|_| Ok(self)) } } @@ -377,8 +377,8 @@ impl Stream for WaitBody { Some(Ok(chunk)) => Ok(Async::Ready(Some(chunk))), Some(Err(e)) => { let req_err = match e { - wait::Waited::TimedOut => ::error::timedout(None), - wait::Waited::Executor(e) => ::error::from(e), + wait::Waited::TimedOut => crate::error::timedout(None), + wait::Waited::Executor(e) => crate::error::from(e), wait::Waited::Inner(e) => e, }; diff --git a/src/tls.rs b/src/tls.rs index 9860d58..7a81ff5 100644 --- a/src/tls.rs +++ b/src/tls.rs @@ -52,7 +52,7 @@ impl Certificate { /// # Ok(()) /// # } /// ``` - pub fn from_der(der: &[u8]) -> ::Result { + pub fn from_der(der: &[u8]) -> crate::Result { Ok(Certificate { #[cfg(feature = "default-tls")] native: try_!(::native_tls::Certificate::from_der(der)), @@ -78,7 +78,7 @@ impl Certificate { /// # Ok(()) /// # } /// ``` - pub fn from_pem(pem: &[u8]) -> ::Result { + pub fn from_pem(pem: &[u8]) -> crate::Result { Ok(Certificate { #[cfg(feature = "default-tls")] native: try_!(::native_tls::Certificate::from_pem(pem)), @@ -149,7 +149,7 @@ impl Identity { /// # } /// ``` #[cfg(feature = "default-tls")] - pub fn from_pkcs12_der(der: &[u8], password: &str) -> ::Result { + pub fn from_pkcs12_der(der: &[u8], password: &str) -> crate::Result { Ok(Identity { inner: ClientCert::Pkcs12( try_!(::native_tls::Identity::from_pkcs12(der, password)) @@ -218,7 +218,7 @@ impl Identity { pub(crate) fn add_to_native_tls( self, tls: &mut ::native_tls::TlsConnectorBuilder, - ) -> ::Result<()> { + ) -> crate::Result<()> { match self.inner { ClientCert::Pkcs12(id) => { tls.identity(id); diff --git a/tests/async.rs b/tests/async.rs index f39678f..d9ddd80 100644 --- a/tests/async.rs +++ b/tests/async.rs @@ -14,8 +14,8 @@ use std::time::Duration; use futures::{Future, Stream}; use tokio::runtime::current_thread::Runtime; -use reqwest::async::Client; -use reqwest::async::multipart::{Form, Part}; +use reqwest::r#async::Client; +use reqwest::r#async::multipart::{Form, Part}; use bytes::Bytes; diff --git a/tests/cookie.rs b/tests/cookie.rs index c7e7dc1..8e91c47 100644 --- a/tests/cookie.rs +++ b/tests/cookie.rs @@ -6,7 +6,7 @@ mod support; #[test] fn cookie_response_accessor() { let mut rt = tokio::runtime::current_thread::Runtime::new().expect("new rt"); - let client = reqwest::async::Client::new(); + let client = reqwest::r#async::Client::new(); let server = server! { request: b"\ @@ -81,7 +81,7 @@ fn cookie_response_accessor() { #[test] fn cookie_store_simple() { let mut rt = tokio::runtime::current_thread::Runtime::new().expect("new rt"); - let client = reqwest::async::Client::builder().cookie_store(true).build().unwrap(); + let client = reqwest::r#async::Client::builder().cookie_store(true).build().unwrap(); let server = server! { request: b"\ @@ -125,7 +125,7 @@ fn cookie_store_simple() { #[test] fn cookie_store_overwrite_existing() { let mut rt = tokio::runtime::current_thread::Runtime::new().expect("new rt"); - let client = reqwest::async::Client::builder().cookie_store(true).build().unwrap(); + let client = reqwest::r#async::Client::builder().cookie_store(true).build().unwrap(); let server = server! { request: b"\ @@ -189,7 +189,7 @@ fn cookie_store_overwrite_existing() { #[test] fn cookie_store_max_age() { let mut rt = tokio::runtime::current_thread::Runtime::new().expect("new rt"); - let client = reqwest::async::Client::builder().cookie_store(true).build().unwrap(); + let client = reqwest::r#async::Client::builder().cookie_store(true).build().unwrap(); let server = server! { request: b"\ @@ -232,7 +232,7 @@ fn cookie_store_max_age() { #[test] fn cookie_store_expires() { let mut rt = tokio::runtime::current_thread::Runtime::new().expect("new rt"); - let client = reqwest::async::Client::builder().cookie_store(true).build().unwrap(); + let client = reqwest::r#async::Client::builder().cookie_store(true).build().unwrap(); let server = server! { request: b"\ @@ -275,7 +275,7 @@ fn cookie_store_expires() { #[test] fn cookie_store_path() { let mut rt = tokio::runtime::current_thread::Runtime::new().expect("new rt"); - let client = reqwest::async::Client::builder().cookie_store(true).build().unwrap(); + let client = reqwest::r#async::Client::builder().cookie_store(true).build().unwrap(); let server = server! { request: b"\ diff --git a/tests/support/server.rs b/tests/support/server.rs index 6c7d073..0b39736 100644 --- a/tests/support/server.rs +++ b/tests/support/server.rs @@ -196,14 +196,14 @@ macro_rules! server { $($f: $v,)+ }),* ]; - ::support::server::spawn(txns) + crate::support::server::spawn(txns) }) } #[macro_export] macro_rules! __internal__txn { ($($field:ident: $val:expr,)+) => ( - ::support::server::Txn { + crate::support::server::Txn { $( $field: __internal__prop!($field: $val), )+ .. Default::default() }