From 96a6ad34a0331e36c059a7080cfb0518e9881935 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Tue, 6 Aug 2024 20:27:12 +0400 Subject: [PATCH] style: cargo clippy --fix --- examples/main.rs | 4 ++-- src/builder.rs | 8 +++++++- src/certs/insecure.rs | 2 +- src/certs/verifier.rs | 2 +- src/client.rs | 8 ++++---- src/response.rs | 18 +++++++++--------- src/status.rs | 8 ++++---- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/examples/main.rs b/examples/main.rs index 0a7ef53..eeaf751 100644 --- a/examples/main.rs +++ b/examples/main.rs @@ -182,8 +182,8 @@ impl SelfsignedCertVerifier for CertVerifier { ); f.write_all(host.as_bytes())?; f.write_all(b" 0 sha512 ")?; // TODO after implementing `expires` - f.write_all(&this_fp.as_bytes())?; - f.write(b"\n")?; + f.write_all(this_fp.as_bytes())?; + f.write_all(b"\n")?; Ok::<(), std::io::Error>(()) })() .unwrap_or_else(|e| { diff --git a/src/builder.rs b/src/builder.rs index 670e2de..a11c093 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -19,6 +19,12 @@ pub struct ClientBuilder { tls_versions: Option<&'static [&'static SupportedProtocolVersion]>, } +impl Default for ClientBuilder { + fn default() -> Self { + Self::new() + } +} + impl ClientBuilder { pub fn new() -> Self { ClientBuilder { @@ -31,7 +37,7 @@ impl ClientBuilder { pub fn build(self) -> Client { let provider = rustls::crypto::CryptoProvider::get_default() - .map(|c| c.clone()) + .cloned() .unwrap_or_else(|| Arc::new(rustls::crypto::ring::default_provider())); let tls_config = rustls::ClientConfig::builder_with_provider(provider.clone()) diff --git a/src/certs/insecure.rs b/src/certs/insecure.rs index ae4a48d..5aa594e 100644 --- a/src/certs/insecure.rs +++ b/src/certs/insecure.rs @@ -11,7 +11,7 @@ impl AllowAllCertVerifier { pub fn yes_i_know_what_i_am_doing() -> Self { AllowAllCertVerifier( CryptoProvider::get_default() - .map(|c| c.clone()) + .cloned() .unwrap_or_else(|| std::sync::Arc::new(rustls::crypto::ring::default_provider())), ) } diff --git a/src/certs/verifier.rs b/src/certs/verifier.rs index 4635dd3..795c890 100644 --- a/src/certs/verifier.rs +++ b/src/certs/verifier.rs @@ -68,7 +68,7 @@ impl ServerCertVerifier for CustomCertVerifier { // (probably with rustls-webpki's webpki::Cert) if self .ss_verifier - .verify(end_entity, &server_name.to_str().as_ref(), now)? + .verify(end_entity, server_name.to_str().as_ref(), now)? { return Ok(ServerCertVerified::assertion()); } diff --git a/src/client.rs b/src/client.rs index fead612..c4e44ce 100644 --- a/src/client.rs +++ b/src/client.rs @@ -44,8 +44,8 @@ impl Client { } impl Client { - pub async fn request(self: &Self, url_str: &str) -> Result { - let url = Url::parse(url_str).map_err(|e| InvalidUrl::ParseError(e))?; + pub async fn request(&self, url_str: &str) -> Result { + let url = Url::parse(url_str).map_err(InvalidUrl::ParseError)?; // for proxying http(s) through gemini server, // use Client::request_with_host if url.scheme() != "gemini" { @@ -64,7 +64,7 @@ impl Client { } pub async fn request_with_host( - self: &Self, + &self, url_str: &str, host: &str, port: u16, @@ -111,7 +111,7 @@ impl Client { // ...otherwise, CR is a part of message, not a CRLF terminator, // so append that one byte that's supposed to be LF (but not LF) // to the message buffer - result.push(buf[0].into()); + result.push(buf[0]); } } diff --git a/src/response.rs b/src/response.rs index c33b792..a3e6cff 100644 --- a/src/response.rs +++ b/src/response.rs @@ -22,11 +22,11 @@ impl Response { } #[inline] - pub fn is_ok(self: &Self) -> bool { + pub fn is_ok(&self) -> bool { self.status.reply_type() == ReplyType::Success } - pub fn ensure_ok(self: Self) -> Result { + pub fn ensure_ok(self) -> Result { if self.status.reply_type() == ReplyType::Success { Ok(self) } else { @@ -34,29 +34,29 @@ impl Response { } } - pub fn status(self: &Self) -> Status { + pub fn status(&self) -> Status { self.status } - pub fn message(self: &Self) -> &str { + pub fn message(&self) -> &str { &self.message } - pub fn mime(self: &Self) -> Result { - self.message.parse().map_err(|e| LibError::InvalidMime(e)) + pub fn mime(&self) -> Result { + self.message.parse().map_err(LibError::InvalidMime) } - pub fn stream(self: &mut Self) -> &mut BodyStream { + pub fn stream(&mut self) -> &mut BodyStream { &mut self.stream } - pub async fn bytes(self: &mut Self) -> Result { + pub async fn bytes(&mut self) -> Result { let mut buf = Vec::new(); self.stream.read_to_end(&mut buf).await?; Ok(Bytes::from(buf)) } - pub async fn text(self: &mut Self) -> Result { + pub async fn text(&mut self) -> Result { let mut buf = String::new(); self.stream.read_to_string(&mut buf).await?; Ok(buf) diff --git a/src/status.rs b/src/status.rs index 9bf41b0..eec1ab1 100644 --- a/src/status.rs +++ b/src/status.rs @@ -77,19 +77,19 @@ impl Status { }) } - pub fn status_code(self: &Self) -> StatusCode { + pub fn status_code(&self) -> StatusCode { self.status_code } - pub fn num(self: &Self) -> u8 { + pub fn num(&self) -> u8 { self.status_code.into() } - pub fn reply_type(self: &Self) -> ReplyType { + pub fn reply_type(&self) -> ReplyType { self.reply_type } - pub fn second_digit(self: &Self) -> u8 { + pub fn second_digit(&self) -> u8 { self.second_digit } }