Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix clippy #817

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions core/src/client/async_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ async fn handle_backend_messages<S: TransportSenderT, R: TransportReceiverT>(
max_notifs_per_subscription: usize,
) -> Result<(), Error> {
// Single response to a request.
if let Ok(single) = serde_json::from_slice::<Response<_>>(&raw) {
if let Ok(single) = serde_json::from_slice::<Response<_>>(raw) {
match process_single_response(manager, single, max_notifs_per_subscription) {
Ok(Some(unsub)) => {
stop_subscription(sender, manager, unsub).await;
Expand All @@ -460,34 +460,34 @@ async fn handle_backend_messages<S: TransportSenderT, R: TransportReceiverT>(
}
}
// Subscription response.
else if let Ok(response) = serde_json::from_slice::<SubscriptionResponse<_>>(&raw) {
else if let Ok(response) = serde_json::from_slice::<SubscriptionResponse<_>>(raw) {
if let Err(Some(unsub)) = process_subscription_response(manager, response) {
let _ = stop_subscription(sender, manager, unsub).await;
stop_subscription(sender, manager, unsub).await;
}
}
// Subscription error response.
else if let Ok(response) = serde_json::from_slice::<SubscriptionError<_>>(&raw) {
else if let Ok(response) = serde_json::from_slice::<SubscriptionError<_>>(raw) {
let _ = process_subscription_close_response(manager, response);
}
// Incoming Notification
else if let Ok(notif) = serde_json::from_slice::<Notification<_>>(&raw) {
else if let Ok(notif) = serde_json::from_slice::<Notification<_>>(raw) {
let _ = process_notification(manager, notif);
}
// Batch response.
else if let Ok(batch) = serde_json::from_slice::<Vec<Response<_>>>(&raw) {
else if let Ok(batch) = serde_json::from_slice::<Vec<Response<_>>>(raw) {
if let Err(e) = process_batch_response(manager, batch) {
return Err(e);
}
}
// Error response
else if let Ok(err) = serde_json::from_slice::<ErrorResponse>(&raw) {
else if let Ok(err) = serde_json::from_slice::<ErrorResponse>(raw) {
if let Err(e) = process_error_response(manager, err) {
return Err(e);
}
}
// Unparsable response
else {
let json = serde_json::from_slice::<serde_json::Value>(&raw);
let json = serde_json::from_slice::<serde_json::Value>(raw);

let json_str = match json {
Ok(json) => serde_json::to_string(&json).expect("valid JSON; qed"),
Expand Down Expand Up @@ -519,7 +519,7 @@ async fn handle_backend_messages<S: TransportSenderT, R: TransportReceiverT>(
}
}

return Ok(());
Ok(())
}

/// Handle frontend messages.
Expand Down
2 changes: 1 addition & 1 deletion core/src/http_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn get_cors_request_headers<'a>(headers: &'a hyper::header::HeaderMap) -> im
read_header_values(headers, ACCESS_CONTROL_REQUEST_HEADERS)
.iter()
.filter_map(|val| val.to_str().ok())
.flat_map(|val| val.split(","))
.flat_map(|val| val.split(','))
// The strings themselves might contain leading and trailing whitespaces
.map(|s| s.trim())
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/server/rpc_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ impl<Context: Send + Sync + 'static> RpcModule<Context> {
let (tx, rx) = oneshot::channel();

let sink = SubscriptionSink {
inner: method_sink.clone(),
inner: method_sink,
close_notify: Some(conn.close_notify),
method: notif_method_name,
subscribers: subscribers.clone(),
Expand All @@ -780,7 +780,7 @@ impl<Context: Send + Sync + 'static> RpcModule<Context> {
};

// The callback returns a `SubscriptionResult` for better ergonomics and is not propagated further.
if let Err(_) = callback(params, sink, ctx.clone()) {
if callback(params, sink, ctx.clone()).is_err() {
tracing::warn!("subscribe call `{}` failed", subscribe_method_name);
}

Expand Down
11 changes: 5 additions & 6 deletions http-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<M> Builder<M> {
/// fn on_request(&self, _remote_addr: SocketAddr, _headers: &Headers) -> Instant {
/// Instant::now()
/// }
///
///
/// // Called once a single JSON-RPC method call is processed, it may be called multiple times
/// // on batches.
/// fn on_call(&self, method_name: &str, params: Params) {
Expand All @@ -129,7 +129,7 @@ impl<M> Builder<M> {
/// println!("Call to '{}' took {:?}", method_name, started_at.elapsed());
/// }
///
/// // Called the entire JSON-RPC is completed, called on once for both single calls or batches.
/// // Called the entire JSON-RPC is completed, called on once for both single calls or batches.
/// fn on_response(&self, result: &str, started_at: Instant) {
/// println!("complete JSON-RPC response: {}, took: {:?}", result, started_at.elapsed());
/// }
Expand Down Expand Up @@ -204,11 +204,11 @@ impl<M> Builder<M> {
pub fn health_api(mut self, path: impl Into<String>, method: impl Into<String>) -> Result<Self, Error> {
let path = path.into();

if !path.starts_with("/") {
if !path.starts_with('/') {
return Err(Error::Custom(format!("Health endpoint path must start with `/` to work, got: {}", path)));
}

self.health_api = Some(HealthApi { path: path, method: method.into() });
self.health_api = Some(HealthApi { path, method: method.into() });
Ok(self)
}

Expand Down Expand Up @@ -776,8 +776,7 @@ where

let response = execute_call(Call { name: &req.method, params, id: req.id, call }).await;

let batch = batch_response.append(&response);
batch
batch_response.append(&response)
},
)
.in_current_span()
Expand Down
4 changes: 2 additions & 2 deletions proc-macros/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ pub(crate) fn generate_where_clause(
let additional_where_clause = item_trait.generics.where_clause.clone();

if let Some(custom_bounds) = bounds {
let mut bounds = additional_where_clause
let mut bounds: Vec<_> = additional_where_clause
.map(|where_clause| where_clause.predicates.into_iter().collect())
.unwrap_or(Vec::new());
.unwrap_or_default();

bounds.extend(custom_bounds.iter().cloned());

Expand Down
12 changes: 6 additions & 6 deletions ws-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,27 +693,27 @@ impl<M> Builder<M> {
/// type Instant = Instant;
///
/// fn on_connect(&self, remote_addr: SocketAddr, headers: &Headers) {
/// println!("[MyMiddleware::on_call] remote_addr: {}, headers: {:?}", remote_addr, headers);
/// println!("[MyMiddleware::on_call] remote_addr: {}, headers: {:?}", remote_addr, headers);
/// }
///
/// fn on_request(&self) -> Self::Instant {
/// Instant::now()
/// Instant::now()
/// }
///
/// fn on_call(&self, method_name: &str, params: Params) {
/// println!("[MyMiddleware::on_call] method: '{}' params: {:?}", method_name, params);
/// println!("[MyMiddleware::on_call] method: '{}' params: {:?}", method_name, params);
/// }
///
/// fn on_result(&self, method_name: &str, success: bool, started_at: Self::Instant) {
/// println!("[MyMiddleware::on_result] '{}', worked? {}, time elapsed {:?}", method_name, success, started_at.elapsed());
/// println!("[MyMiddleware::on_result] '{}', worked? {}, time elapsed {:?}", method_name, success, started_at.elapsed());
/// }
///
/// fn on_response(&self, result: &str, started_at: Self::Instant) {
/// println!("[MyMiddleware::on_response] result: {}, time elapsed {:?}", result, started_at.elapsed());
/// println!("[MyMiddleware::on_response] result: {}, time elapsed {:?}", result, started_at.elapsed());
/// }
///
/// fn on_disconnect(&self, remote_addr: SocketAddr) {
/// println!("[MyMiddleware::on_disconnect] remote_addr: {}", remote_addr);
/// println!("[MyMiddleware::on_disconnect] remote_addr: {}", remote_addr);
/// }
/// }
///
Expand Down