From 6a88c2c8bfbb0bac97029265a42703a17c76e01c Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sat, 12 Sep 2020 18:42:15 -0700 Subject: [PATCH] Clean up unused code and long imports. (#137) This removes some commented out methods, and also changes instances of ::std::foo to use a more idiomatic import path. --- src/agent.rs | 7 ++++--- src/body.rs | 9 +++++---- src/header.rs | 5 +++-- src/request.rs | 38 ++++---------------------------------- src/response.rs | 5 +++-- src/stream.rs | 5 +++-- 6 files changed, 22 insertions(+), 47 deletions(-) diff --git a/src/agent.rs b/src/agent.rs index 4eaf6d1..5d2ef15 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -256,20 +256,21 @@ pub(crate) fn basic_auth(user: &str, pass: &str) -> String { Some(idx) => &user[..idx], None => user, }; - ::base64::encode(&format!("{}:{}", safe, pass)) + base64::encode(&format!("{}:{}", safe, pass)) } #[cfg(test)] mod tests { use super::*; use std::io::Read; + use std::thread; ///////////////////// AGENT TESTS ////////////////////////////// #[test] fn agent_implements_send() { let mut agent = Agent::new(); - ::std::thread::spawn(move || { + thread::spawn(move || { agent.set("Foo", "Bar"); }); } @@ -309,7 +310,7 @@ mod tests { fn request_implements_send() { let agent = Agent::new(); let mut request = Request::new(&agent, "GET".to_string(), "/foo".to_string()); - ::std::thread::spawn(move || { + thread::spawn(move || { request.set("Foo", "Bar"); }); } diff --git a/src/body.rs b/src/body.rs index f87763e..b6b188f 100644 --- a/src/body.rs +++ b/src/body.rs @@ -1,4 +1,5 @@ use crate::stream::Stream; +use std::fmt; use std::io::{copy, empty, Cursor, Read, Result as IoResult, Write}; #[cfg(feature = "charset")] @@ -23,8 +24,8 @@ pub(crate) enum Payload { Bytes(Vec), } -impl ::std::fmt::Debug for Payload { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> { +impl fmt::Debug for Payload { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Payload::Empty => write!(f, "Empty"), Payload::Text(t, _) => write!(f, "{}", t), @@ -50,8 +51,8 @@ pub(crate) struct SizedReader { pub reader: Box, } -impl ::std::fmt::Debug for SizedReader { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> { +impl fmt::Debug for SizedReader { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "SizedReader[size={:?},reader]", self.size) } } diff --git a/src/header.rs b/src/header.rs index b788c39..bf3dfed 100644 --- a/src/header.rs +++ b/src/header.rs @@ -1,4 +1,5 @@ use crate::error::Error; +use std::fmt; use std::str::FromStr; #[derive(Clone, PartialEq)] @@ -14,8 +15,8 @@ pub struct Header { index: usize, } -impl ::std::fmt::Debug for Header { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> { +impl fmt::Debug for Header { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.line) } } diff --git a/src/request.rs b/src/request.rs index 036ec73..8a8b44e 100644 --- a/src/request.rs +++ b/src/request.rs @@ -1,16 +1,12 @@ +use std::fmt; use std::io::Read; +use std::result::Result; use std::sync::{Arc, Mutex}; use std::time; use qstring::QString; use url::{form_urlencoded, Url}; -#[cfg(feature = "tls")] -use std::fmt; - -#[cfg(all(feature = "native-tls", not(feature = "tls")))] -use std::fmt; - use crate::agent::{self, Agent, AgentState}; use crate::body::{Payload, SizedReader}; use crate::error::Error; @@ -54,8 +50,8 @@ pub struct Request { pub(crate) tls_connector: Option, } -impl ::std::fmt::Debug for Request { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> { +impl fmt::Debug for Request { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let (path, query) = self .to_url() .map(|u| { @@ -462,32 +458,6 @@ impl Request { self } - // pub fn retry(&self, times: u16) -> Request { - // unimplemented!() - // } - // pub fn sortQuery(&self) -> Request { - // unimplemented!() - // } - // pub fn sortQueryBy(&self, by: Box usize>) -> Request { - // unimplemented!() - // } - // pub fn ca(&self, accept: S) -> Request - // where S: Into { - // unimplemented!() - // } - // pub fn cert(&self, accept: S) -> Request - // where S: Into { - // unimplemented!() - // } - // pub fn key(&self, accept: S) -> Request - // where S: Into { - // unimplemented!() - // } - // pub fn pfx(&self, accept: S) -> Request // TODO what type? u8? - // where S: Into { - // unimplemented!() - // } - /// Get the method this request is using. /// /// Example: diff --git a/src/response.rs b/src/response.rs index 60c41d1..4e2d1c2 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,3 +1,4 @@ +use std::fmt; use std::io::{Cursor, Error as IoError, ErrorKind, Read, Result as IoResult}; use std::str::FromStr; use std::time::Instant; @@ -65,8 +66,8 @@ struct ResponseStatusIndex { response_code: usize, } -impl ::std::fmt::Debug for Response { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> { +impl fmt::Debug for Response { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "Response[status: {}, status_text: {}]", diff --git a/src/stream.rs b/src/stream.rs index 599f7e5..b0f8309 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -1,3 +1,4 @@ +use std::fmt; use std::io::{ BufRead, BufReader, Cursor, Error as IoError, ErrorKind, Read, Result as IoResult, Write, }; @@ -102,8 +103,8 @@ pub(crate) fn io_err_timeout(error: String) -> IoError { IoError::new(ErrorKind::TimedOut, error) } -impl ::std::fmt::Debug for Stream { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> { +impl fmt::Debug for Stream { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "Stream[{}]",