Skip to content

Commit

Permalink
refactor(client): small refactoring (#88)
Browse files Browse the repository at this point in the history
* refactor(client): remove reference to reference

* refactor(client): remove unnecessary clone

* refactor(client): use some api instead of manual implementaion
  • Loading branch information
tottoto authored Jan 14, 2024
1 parent 784109d commit da6e35b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/client/legacy/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ where
impl<C: Clone, B> Clone for Client<C, B> {
fn clone(&self) -> Client<C, B> {
Client {
config: self.config.clone(),
config: self.config,
exec: self.exec.clone(),
#[cfg(feature = "http1")]
h1_builder: self.h1_builder.clone(),
Expand Down Expand Up @@ -925,7 +925,7 @@ fn set_scheme(uri: &mut Uri, scheme: Scheme) {
uri.scheme().is_none(),
"set_scheme expects no existing scheme"
);
let old = std::mem::replace(uri, Uri::default());
let old = std::mem::take(uri);
let mut parts: ::http::uri::Parts = old.into();
parts.scheme = Some(scheme);
parts.path_and_query = Some("/".parse().expect("slash is a valid path"));
Expand Down
4 changes: 1 addition & 3 deletions src/client/legacy/connect/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,7 @@ struct ConnectingTcpRemote {

impl ConnectingTcpRemote {
fn new(addrs: dns::SocketAddrs, connect_timeout: Option<Duration>) -> Self {
let connect_timeout = connect_timeout
.map(|t| t.checked_div(addrs.len() as u32))
.flatten();
let connect_timeout = connect_timeout.and_then(|t| t.checked_div(addrs.len() as u32));

Self {
addrs,
Expand Down
2 changes: 1 addition & 1 deletion src/client/legacy/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl<T: Poolable, K: Key> PoolInner<T, K> {
Some(value) => {
// borrow-check scope...
{
let idle_list = self.idle.entry(key.clone()).or_insert_with(Vec::new);
let idle_list = self.idle.entry(key.clone()).or_default();
if self.max_idle_per_host <= idle_list.len() {
trace!("max idle per host for {:?}, dropping connection", key);
return;
Expand Down
8 changes: 2 additions & 6 deletions src/server/conn/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,7 @@ pub struct Http1Builder<'a, E> {
impl<E> Http1Builder<'_, E> {
/// Http2 configuration.
pub fn http2(&mut self) -> Http2Builder<'_, E> {
Http2Builder {
inner: &mut self.inner,
}
Http2Builder { inner: self.inner }
}

/// Set whether HTTP/1 connections should support half-closures.
Expand Down Expand Up @@ -546,9 +544,7 @@ pub struct Http2Builder<'a, E> {
impl<E> Http2Builder<'_, E> {
/// Http1 configuration.
pub fn http1(&mut self) -> Http1Builder<'_, E> {
Http1Builder {
inner: &mut self.inner,
}
Http1Builder { inner: self.inner }
}

/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
Expand Down

0 comments on commit da6e35b

Please sign in to comment.