Skip to content

Commit

Permalink
chore: address clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sleeyax committed Dec 28, 2023
1 parent 8dcbd59 commit 9cb60c6
Show file tree
Hide file tree
Showing 23 changed files with 109 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/buffer_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};

static mut BUFFER_CALLBACKS: Lazy<CronetCallbacks<Cronet_BufferCallbackPtr, BufferCallbackFn>> =
Lazy::new(|| CronetCallbacks::new());
Lazy::new(CronetCallbacks::new);

#[no_mangle]
unsafe extern "C" fn cronetBufferCallbackOnDestroy(
Expand Down
6 changes: 6 additions & 0 deletions src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,9 @@ impl Client {
}
}
}

impl Default for Client {
fn default() -> Self {
Self::new()
}
}
1 change: 1 addition & 0 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod body;
mod body_upload_provider;
#[allow(clippy::module_inception)]
mod client;
mod error;
mod response_handler;
Expand Down
2 changes: 1 addition & 1 deletion src/client/response_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 6 additions & 0 deletions src/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ impl Destroy for Engine {
}
}

impl Default for Engine {
fn default() -> Self {
Self::new()
}
}

#[cfg(test)]
mod tests {
use crate::Destroy;
Expand Down
6 changes: 6 additions & 0 deletions src/engine_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};

static mut EXECUTOR_CALLBACKS: Lazy<CronetCallbacks<Cronet_ExecutorPtr, ExecutorExecuteFn>> =
Lazy::new(|| CronetCallbacks::new());
Lazy::new(CronetCallbacks::new);

#[no_mangle]
unsafe extern "C" fn cronetExecutorOnExecute(
Expand Down
6 changes: 6 additions & 0 deletions src/http_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ impl Destroy for HttpHeader {
}
}

impl Default for HttpHeader {
fn default() -> Self {
Self::new()
}
}

#[cfg(test)]
mod tests {
use crate::Destroy;
Expand Down
21 changes: 9 additions & 12 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/public_key_pins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/quic_hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ impl Destroy for QuicHint {
}
}

impl Default for QuicHint {
fn default() -> Self {
Self::new()
}
}

#[cfg(test)]
mod tests {
use crate::Destroy;
Expand Down
6 changes: 6 additions & 0 deletions src/request_finished_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 7 additions & 6 deletions src/request_finished_info_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{

static mut REQUEST_FINISHED_INFO_LISTENER_CALLBACKS: Lazy<
CronetCallbacks<Cronet_RequestFinishedInfoListenerPtr, OnRequestFinishedFn>,
> = Lazy::new(|| CronetCallbacks::new());
> = Lazy::new(CronetCallbacks::new);

#[no_mangle]
unsafe extern "C" fn cronetOnRequestFinished(
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion src/runnable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};

static mut RUNNABLE_CALLBACKS: Lazy<CronetCallbacks<Cronet_RunnablePtr, RunnableRunFn>> =
Lazy::new(|| CronetCallbacks::new());
Lazy::new(CronetCallbacks::new);

#[no_mangle]
unsafe extern "C" fn cronetRunnableOnRun(selfPtr: Cronet_RunnablePtr) {
Expand Down
9 changes: 5 additions & 4 deletions src/upload_data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use crate::{

static mut UPLOAD_DATA_PROVIDER_CALLBACKS: Lazy<
CronetCallbacks<Cronet_UploadDataProviderPtr, Box<dyn UploadDataProviderHandler>>,
> = Lazy::new(|| CronetCallbacks::new());
> = Lazy::new(CronetCallbacks::new);

#[no_mangle]
unsafe extern "C" fn cronetUploadDataProviderGetLength(
selfPtr: Cronet_UploadDataProviderPtr,
) -> 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]
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/upload_data_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{

static mut UPLOAD_DATA_SINK_CALLBACKS: Lazy<
CronetCallbacks<Cronet_UploadDataSinkPtr, UploadDataSinkCallbacks>,
> = Lazy::new(|| CronetCallbacks::new());
> = Lazy::new(CronetCallbacks::new);

#[no_mangle]
unsafe extern "C" fn cronetUploadDataSinkOnReadSucceeded(
Expand Down
6 changes: 6 additions & 0 deletions src/url_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,9 @@ impl Destroy for UrlRequest {
}
}
}

impl Default for UrlRequest {
fn default() -> Self {
Self::new()
}
}
2 changes: 1 addition & 1 deletion src/url_request_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{

static mut URL_REQUEST_CALLBACK_CALLBACKS: Lazy<
CronetCallbacks<Cronet_UrlRequestCallbackPtr, Box<dyn UrlRequestCallbackHandler>>,
> = Lazy::new(|| CronetCallbacks::new());
> = Lazy::new(CronetCallbacks::new);

#[no_mangle]
unsafe extern "C" fn cronetUrlRequestCallbackOnRedirectReceived(
Expand Down
6 changes: 6 additions & 0 deletions src/url_request_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ impl Destroy for UrlRequestParams {
}
}

impl Default for UrlRequestParams {
fn default() -> Self {
Self::new()
}
}

#[cfg(feature = "client")]
impl<T> From<Request<T>> for UrlRequestParams
where
Expand Down
8 changes: 7 additions & 1 deletion src/url_request_status_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{

static mut URL_REQUEST_STATUS_LISTENER_CALLBACKS: Lazy<
CronetCallbacks<Cronet_UrlRequestStatusListenerPtr, UrlRequestStatusListenerOnStatusFn>,
> = Lazy::new(|| CronetCallbacks::new());
> = Lazy::new(CronetCallbacks::new);

#[no_mangle]
unsafe extern "C" fn cronetUrlRequestStatusListenerOnStatus(
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 8 additions & 4 deletions src/url_response_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<T> Into<Response<T>> for UrlResponseInfo
where
T: Default,
Expand Down

0 comments on commit 9cb60c6

Please sign in to comment.