From 9cb60c6dcf4a8842d482d11316e744187ed331b2 Mon Sep 17 00:00:00 2001 From: Sleeyax Date: Thu, 28 Dec 2023 23:10:37 +0100 Subject: [PATCH] chore: address clippy warnings --- src/buffer_callback.rs | 2 +- src/client/client.rs | 6 ++++++ src/client/mod.rs | 1 + src/client/response_handler.rs | 2 +- src/date_time.rs | 6 ++++++ src/engine.rs | 6 ++++++ src/engine_params.rs | 6 ++++++ src/error.rs | 6 ++++++ src/executor.rs | 2 +- src/http_header.rs | 6 ++++++ src/metrics.rs | 21 +++++++++------------ src/public_key_pins.rs | 6 ++++++ src/quic_hint.rs | 6 ++++++ src/request_finished_info.rs | 6 ++++++ src/request_finished_info_listener.rs | 13 +++++++------ src/runnable.rs | 2 +- src/upload_data_provider.rs | 9 +++++---- src/upload_data_sink.rs | 2 +- src/url_request.rs | 6 ++++++ src/url_request_callback.rs | 2 +- src/url_request_params.rs | 6 ++++++ src/url_request_status_listener.rs | 8 +++++++- src/url_response_info.rs | 12 ++++++++---- 23 files changed, 109 insertions(+), 33 deletions(-) diff --git a/src/buffer_callback.rs b/src/buffer_callback.rs index 13cc888..78c00ca 100644 --- a/src/buffer_callback.rs +++ b/src/buffer_callback.rs @@ -6,7 +6,7 @@ use crate::{ }; static mut BUFFER_CALLBACKS: Lazy> = - Lazy::new(|| CronetCallbacks::new()); + Lazy::new(CronetCallbacks::new); #[no_mangle] unsafe extern "C" fn cronetBufferCallbackOnDestroy( diff --git a/src/client/client.rs b/src/client/client.rs index 33f2aee..5e942cb 100644 --- a/src/client/client.rs +++ b/src/client/client.rs @@ -84,3 +84,9 @@ impl Client { } } } + +impl Default for Client { + fn default() -> Self { + Self::new() + } +} diff --git a/src/client/mod.rs b/src/client/mod.rs index e3d8660..c0d9d4a 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1,5 +1,6 @@ mod body; mod body_upload_provider; +#[allow(clippy::module_inception)] mod client; mod error; mod response_handler; diff --git a/src/client/response_handler.rs b/src/client/response_handler.rs index dc54726..f4aa55e 100644 --- a/src/client/response_handler.rs +++ b/src/client/response_handler.rs @@ -102,7 +102,7 @@ impl UrlRequestCallbackHandler for ResponseHandler { fn on_succeeded(&mut self, _: UrlRequestCallback, req: UrlRequest, _: UrlResponseInfo) { req.destroy(); - let response = mem::replace(&mut self.response, Response::default()); + let response = mem::take(&mut self.response); self.tx.send(Status::Success(response)).unwrap(); } diff --git a/src/date_time.rs b/src/date_time.rs index f3bfc57..ada7bea 100644 --- a/src/date_time.rs +++ b/src/date_time.rs @@ -48,6 +48,12 @@ impl Destroy for DateTime { } } +impl Default for DateTime { + fn default() -> Self { + Self::new() + } +} + #[cfg(test)] mod tests { use std::time::UNIX_EPOCH; diff --git a/src/engine.rs b/src/engine.rs index 68b3a98..b10bb4c 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -110,6 +110,12 @@ impl Destroy for Engine { } } +impl Default for Engine { + fn default() -> Self { + Self::new() + } +} + #[cfg(test)] mod tests { use crate::Destroy; diff --git a/src/engine_params.rs b/src/engine_params.rs index b45c889..5863d84 100644 --- a/src/engine_params.rs +++ b/src/engine_params.rs @@ -273,6 +273,12 @@ impl Destroy for EngineParams { } } +impl Default for EngineParams { + fn default() -> Self { + Self::new() + } +} + #[derive(Debug, PartialEq)] pub enum HttpCacheMode { /// Disable HTTP cache. diff --git a/src/error.rs b/src/error.rs index ef544a4..630b4b4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -116,6 +116,12 @@ impl Destroy for CronetError { } } +impl Default for CronetError { + fn default() -> Self { + Self::new() + } +} + impl fmt::Display for CronetError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( diff --git a/src/executor.rs b/src/executor.rs index 8eaf4ee..1fe9983 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -6,7 +6,7 @@ use crate::{ }; static mut EXECUTOR_CALLBACKS: Lazy> = - Lazy::new(|| CronetCallbacks::new()); + Lazy::new(CronetCallbacks::new); #[no_mangle] unsafe extern "C" fn cronetExecutorOnExecute( diff --git a/src/http_header.rs b/src/http_header.rs index 0f3dd8c..9c4b6ae 100644 --- a/src/http_header.rs +++ b/src/http_header.rs @@ -58,6 +58,12 @@ impl Destroy for HttpHeader { } } +impl Default for HttpHeader { + fn default() -> Self { + Self::new() + } +} + #[cfg(test)] mod tests { use crate::Destroy; diff --git a/src/metrics.rs b/src/metrics.rs index 155fa48..3da3ed8 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -161,24 +161,15 @@ impl Metrics { } pub fn socket_reused(&self) -> bool { - unsafe { - let reused = Cronet_Metrics_socket_reused_get(self.ptr); - reused - } + unsafe { Cronet_Metrics_socket_reused_get(self.ptr) } } pub fn sent_byte_count(&self) -> i64 { - unsafe { - let count = Cronet_Metrics_sent_byte_count_get(self.ptr); - count - } + unsafe { Cronet_Metrics_sent_byte_count_get(self.ptr) } } pub fn received_byte_count(&self) -> i64 { - unsafe { - let count = Cronet_Metrics_received_byte_count_get(self.ptr); - count - } + unsafe { Cronet_Metrics_received_byte_count_get(self.ptr) } } pub fn set_request_start(&self, datetime: DateTime) { @@ -284,6 +275,12 @@ impl Destroy for Metrics { } } +impl Default for Metrics { + fn default() -> Self { + Self::new() + } +} + #[cfg(test)] mod tests { use std::time::SystemTime; diff --git a/src/public_key_pins.rs b/src/public_key_pins.rs index 07d450a..6c26210 100644 --- a/src/public_key_pins.rs +++ b/src/public_key_pins.rs @@ -111,6 +111,12 @@ impl Destroy for PublicKeyPins { } } +impl Default for PublicKeyPins { + fn default() -> Self { + Self::new() + } +} + #[cfg(test)] mod tests { use std::time::UNIX_EPOCH; diff --git a/src/quic_hint.rs b/src/quic_hint.rs index eb2ac6b..a021548 100644 --- a/src/quic_hint.rs +++ b/src/quic_hint.rs @@ -65,6 +65,12 @@ impl Destroy for QuicHint { } } +impl Default for QuicHint { + fn default() -> Self { + Self::new() + } +} + #[cfg(test)] mod tests { use crate::Destroy; diff --git a/src/request_finished_info.rs b/src/request_finished_info.rs index 8d3ddcf..3cc3123 100644 --- a/src/request_finished_info.rs +++ b/src/request_finished_info.rs @@ -87,6 +87,12 @@ impl Destroy for RequestFinishedInfo { } } +impl Default for RequestFinishedInfo { + fn default() -> Self { + Self::new() + } +} + /// Enum representing the reason why the request finished. #[derive(Debug, PartialEq)] pub enum RequestFinishedInfoReason { diff --git a/src/request_finished_info_listener.rs b/src/request_finished_info_listener.rs index e036e79..1f38676 100644 --- a/src/request_finished_info_listener.rs +++ b/src/request_finished_info_listener.rs @@ -10,7 +10,7 @@ use crate::{ static mut REQUEST_FINISHED_INFO_LISTENER_CALLBACKS: Lazy< CronetCallbacks, -> = Lazy::new(|| CronetCallbacks::new()); +> = Lazy::new(CronetCallbacks::new); #[no_mangle] unsafe extern "C" fn cronetOnRequestFinished( @@ -50,10 +50,9 @@ impl RequestFinishedInfoListener { } } - pub fn set_client_context(&self, raw_data: Cronet_RawDataPtr) { - unsafe { - Cronet_RequestFinishedInfoListener_SetClientContext(self.ptr, raw_data); - } + #[allow(clippy::missing_safety_doc)] + pub unsafe fn set_client_context(&self, raw_data: Cronet_RawDataPtr) { + Cronet_RequestFinishedInfoListener_SetClientContext(self.ptr, raw_data); } } @@ -84,7 +83,9 @@ mod tests { #[test] fn it_sets_client_context() { let listener = super::RequestFinishedInfoListener::new(|_, _, _, _| {}); - listener.set_client_context(std::ptr::null_mut()); + unsafe { + listener.set_client_context(std::ptr::null_mut()); + } listener.destroy(); } } diff --git a/src/runnable.rs b/src/runnable.rs index bbe5e96..3a9e1d7 100644 --- a/src/runnable.rs +++ b/src/runnable.rs @@ -6,7 +6,7 @@ use crate::{ }; static mut RUNNABLE_CALLBACKS: Lazy> = - Lazy::new(|| CronetCallbacks::new()); + Lazy::new(CronetCallbacks::new); #[no_mangle] unsafe extern "C" fn cronetRunnableOnRun(selfPtr: Cronet_RunnablePtr) { diff --git a/src/upload_data_provider.rs b/src/upload_data_provider.rs index d2e76f5..159276e 100644 --- a/src/upload_data_provider.rs +++ b/src/upload_data_provider.rs @@ -11,7 +11,7 @@ use crate::{ static mut UPLOAD_DATA_PROVIDER_CALLBACKS: Lazy< CronetCallbacks>, -> = Lazy::new(|| CronetCallbacks::new()); +> = Lazy::new(CronetCallbacks::new); #[no_mangle] unsafe extern "C" fn cronetUploadDataProviderGetLength( @@ -19,7 +19,7 @@ unsafe extern "C" fn cronetUploadDataProviderGetLength( ) -> i64 { let lockedMap = UPLOAD_DATA_PROVIDER_CALLBACKS.map().lock().unwrap(); let callback = lockedMap.get(&selfPtr).unwrap(); - return callback.length(UploadDataProvider { ptr: selfPtr }); + callback.length(UploadDataProvider { ptr: selfPtr }) } #[no_mangle] @@ -105,8 +105,9 @@ impl UploadDataProvider { } } - pub fn set_client_context(&self, client_context: Cronet_ClientContext) { - unsafe { Cronet_UploadDataProvider_SetClientContext(self.ptr, client_context) } + #[allow(clippy::missing_safety_doc)] + pub unsafe fn set_client_context(&self, client_context: Cronet_ClientContext) { + Cronet_UploadDataProvider_SetClientContext(self.ptr, client_context) } pub fn client_context(&self) -> Cronet_ClientContext { diff --git a/src/upload_data_sink.rs b/src/upload_data_sink.rs index ba0fe13..e8194f5 100644 --- a/src/upload_data_sink.rs +++ b/src/upload_data_sink.rs @@ -11,7 +11,7 @@ use crate::{ static mut UPLOAD_DATA_SINK_CALLBACKS: Lazy< CronetCallbacks, -> = Lazy::new(|| CronetCallbacks::new()); +> = Lazy::new(CronetCallbacks::new); #[no_mangle] unsafe extern "C" fn cronetUploadDataSinkOnReadSucceeded( diff --git a/src/url_request.rs b/src/url_request.rs index e377572..fd7bdf2 100644 --- a/src/url_request.rs +++ b/src/url_request.rs @@ -134,3 +134,9 @@ impl Destroy for UrlRequest { } } } + +impl Default for UrlRequest { + fn default() -> Self { + Self::new() + } +} diff --git a/src/url_request_callback.rs b/src/url_request_callback.rs index eb9af0b..0170164 100644 --- a/src/url_request_callback.rs +++ b/src/url_request_callback.rs @@ -11,7 +11,7 @@ use crate::{ static mut URL_REQUEST_CALLBACK_CALLBACKS: Lazy< CronetCallbacks>, -> = Lazy::new(|| CronetCallbacks::new()); +> = Lazy::new(CronetCallbacks::new); #[no_mangle] unsafe extern "C" fn cronetUrlRequestCallbackOnRedirectReceived( diff --git a/src/url_request_params.rs b/src/url_request_params.rs index a2eb81d..da8304d 100644 --- a/src/url_request_params.rs +++ b/src/url_request_params.rs @@ -270,6 +270,12 @@ impl Destroy for UrlRequestParams { } } +impl Default for UrlRequestParams { + fn default() -> Self { + Self::new() + } +} + #[cfg(feature = "client")] impl From> for UrlRequestParams where diff --git a/src/url_request_status_listener.rs b/src/url_request_status_listener.rs index 3eae5d5..9dd3097 100644 --- a/src/url_request_status_listener.rs +++ b/src/url_request_status_listener.rs @@ -8,7 +8,7 @@ use crate::{ static mut URL_REQUEST_STATUS_LISTENER_CALLBACKS: Lazy< CronetCallbacks, -> = Lazy::new(|| CronetCallbacks::new()); +> = Lazy::new(CronetCallbacks::new); #[no_mangle] unsafe extern "C" fn cronetUrlRequestStatusListenerOnStatus( @@ -53,6 +53,12 @@ impl Destroy for UrlRequestStatusListener { } } +impl Default for UrlRequestStatusListener { + fn default() -> Self { + Self::new() + } +} + /// Enum representing the status of a [crate::UrlRequest]. #[derive(Debug, PartialEq)] pub enum UrlRequestStatus { diff --git a/src/url_response_info.rs b/src/url_response_info.rs index b69ea18..ccff671 100644 --- a/src/url_response_info.rs +++ b/src/url_response_info.rs @@ -109,10 +109,7 @@ impl UrlResponseInfo { } pub fn header_size(&self) -> u32 { - unsafe { - let size = Cronet_UrlResponseInfo_all_headers_list_size(self.ptr); - size - } + unsafe { Cronet_UrlResponseInfo_all_headers_list_size(self.ptr) } } pub fn header_at(&self, index: u32) -> HttpHeader { @@ -200,7 +197,14 @@ impl Destroy for UrlResponseInfo { } } +impl Default for UrlResponseInfo { + fn default() -> Self { + Self::new() + } +} + #[cfg(feature = "client")] +#[allow(clippy::from_over_into)] impl Into> for UrlResponseInfo where T: Default,