From 8ab23fedd3b766057f36ca2e9f2e0bc2dec6d796 Mon Sep 17 00:00:00 2001 From: PramUkesh Date: Tue, 23 Jan 2024 01:45:06 +0530 Subject: [PATCH] lint: cargo fmt --- src/plugins/websocket/events.rs | 18 ++++++++++++++--- src/plugins/websocket/mod.rs | 36 ++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/plugins/websocket/events.rs b/src/plugins/websocket/events.rs index 7e8e6a5..2db5f8d 100644 --- a/src/plugins/websocket/events.rs +++ b/src/plugins/websocket/events.rs @@ -37,9 +37,21 @@ impl Handler for WebsocketController { #[serde(untagged)] #[serde(rename_all = "camelCase")] pub enum ServerEvent { - Event { cmd: String, id: usize, params: EventType }, - Notification { cmd: String, id: usize, params: Value }, - Confirm { cmd: String, id: usize, params: Value }, + Event { + cmd: String, + id: usize, + params: EventType, + }, + Notification { + cmd: String, + id: usize, + params: Value, + }, + Confirm { + cmd: String, + id: usize, + params: Value, + }, } #[allow(clippy::enum_variant_names)] diff --git a/src/plugins/websocket/mod.rs b/src/plugins/websocket/mod.rs index 721a1a9..35a1bc0 100644 --- a/src/plugins/websocket/mod.rs +++ b/src/plugins/websocket/mod.rs @@ -64,16 +64,16 @@ pub async fn serve_websocket( trace!("Serving websocket"); #[cfg(not(debug_assertions))] { - let origin = req - .headers() - .get(header_name!("origin")) - .and_then(|h| h.to_str().ok()) - .unwrap_or(""); - let host = req - .headers() - .get(header_name!("host")) - .and_then(|h| h.to_str().ok()) - .unwrap_or(""); + let origin = req + .headers() + .get(header_name!("origin")) + .and_then(|h| h.to_str().ok()) + .unwrap_or(""); + let host = req + .headers() + .get(header_name!("host")) + .and_then(|h| h.to_str().ok()) + .unwrap_or(""); let origin_host = origin.split("://").collect::>()[1]; if origin_host != host { //TODO!: and origin_host not in allowed_ws_origins @@ -157,7 +157,7 @@ impl StreamHandler> for ZeruWebsocket { return; } }; - if let Err(err) = self.handle_response(ctx, &cmd_res) { + if let Err(err) = self.handle_response(ctx, &cmd_res) { error!("Error handling response: {:?}", err); } return; @@ -367,12 +367,19 @@ impl ZeruWebsocket { Ok(res) } - fn handle_response(&mut self, ctx: &mut ws::WebsocketContext, response: &CommandResponse) -> Result<(), Error> { + fn handle_response( + &mut self, + ctx: &mut ws::WebsocketContext, + response: &CommandResponse, + ) -> Result<(), Error> { trace!("Handling response: {:?}", response); let id = response.to as usize; let callback = self.waiting_callbacks.remove(&id); if let Some(callback) = callback { - let data = self.callback_data.remove(&id).unwrap_or(response.result.clone()); + let data = self + .callback_data + .remove(&id) + .unwrap_or(response.result.clone()); let command = Command { cmd: CommandType::Response, params: data, @@ -396,7 +403,8 @@ impl ZeruWebsocket { ) -> Result<(), Error> { trace!( "Handling command: {:?} with params: {:?}", - command.cmd, command.params + command.cmd, + command.params ); let response = if let CommandType::UiServer(cmd) = &command.cmd { match cmd {