From b33665d5a8ec6434955c9586c0676e36f01ddacf Mon Sep 17 00:00:00 2001 From: Lena Date: Mon, 16 Dec 2024 09:22:05 +0100 Subject: [PATCH] rustfmt --- axum/src/extract/ws.rs | 19 +++++++++++-------- examples/testing-websockets/src/main.rs | 5 +---- examples/websockets/src/client.rs | 6 ++++-- examples/websockets/src/main.rs | 6 +++++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/axum/src/extract/ws.rs b/axum/src/extract/ws.rs index 493ed2a8457..5708d9ad8d8 100644 --- a/axum/src/extract/ws.rs +++ b/axum/src/extract/ws.rs @@ -114,7 +114,11 @@ use std::{ use tokio_tungstenite::{ tungstenite::{ self as ts, - protocol::{self, frame::{Payload, Utf8Payload}, WebSocketConfig}, + protocol::{ + self, + frame::{Payload, Utf8Payload}, + WebSocketConfig, + }, }, WebSocketStream, }; @@ -677,9 +681,11 @@ impl Message { pub fn into_text(self) -> Result { match self { Self::Text(string) => Ok(string.to_string()), - Self::Binary(data) | Self::Ping(data) | Self::Pong(data) => Ok(String::from_utf8(data.as_slice().to_vec()) - .map_err(|err| err.utf8_error()) - .map_err(Error::new)?), + Self::Binary(data) | Self::Ping(data) | Self::Pong(data) => { + Ok(String::from_utf8(data.as_slice().to_vec()) + .map_err(|err| err.utf8_error()) + .map_err(Error::new)?) + } Self::Close(None) => Ok(String::new()), Self::Close(Some(frame)) => Ok(frame.reason.into_owned()), } @@ -1036,9 +1042,6 @@ mod tests { .await .unwrap(); let output = socket.next().await.unwrap().unwrap(); - assert_eq!( - output, - tungstenite::Message::Pong("ping".as_bytes().into()) - ); + assert_eq!(output, tungstenite::Message::Pong("ping".as_bytes().into())); } } diff --git a/examples/testing-websockets/src/main.rs b/examples/testing-websockets/src/main.rs index 64caeef9834..7a0be11ce41 100644 --- a/examples/testing-websockets/src/main.rs +++ b/examples/testing-websockets/src/main.rs @@ -136,10 +136,7 @@ mod tests { tokio::spawn(unit_testable_handle_socket(socket_write, socket_read)); - test_tx - .send(Ok(Message::Text("foo".into()))) - .await - .unwrap(); + test_tx.send(Ok(Message::Text("foo".into()))).await.unwrap(); let msg = match test_rx.next().await.unwrap() { Message::Text(msg) => msg, diff --git a/examples/websockets/src/client.rs b/examples/websockets/src/client.rs index 74e92c9432a..5a281a138ad 100644 --- a/examples/websockets/src/client.rs +++ b/examples/websockets/src/client.rs @@ -12,10 +12,10 @@ use futures_util::stream::FuturesUnordered; use futures_util::{SinkExt, StreamExt}; -use tokio_tungstenite::tungstenite::protocol::frame::Payload; use std::borrow::Cow; use std::ops::ControlFlow; use std::time::Instant; +use tokio_tungstenite::tungstenite::protocol::frame::Payload; // we will use tungstenite for websocket client impl (same library as what axum is using) use tokio_tungstenite::{ @@ -66,7 +66,9 @@ async fn spawn_client(who: usize) { //we can ping the server for start sender - .send(Message::Ping(Payload::Shared("Hello, Server!".as_bytes().into()))) + .send(Message::Ping(Payload::Shared( + "Hello, Server!".as_bytes().into(), + ))) .await .expect("Can not send!"); diff --git a/examples/websockets/src/main.rs b/examples/websockets/src/main.rs index 5f487ebcab9..2403bb93cfe 100644 --- a/examples/websockets/src/main.rs +++ b/examples/websockets/src/main.rs @@ -101,7 +101,11 @@ async fn ws_handler( /// Actual websocket statemachine (one will be spawned per connection) async fn handle_socket(mut socket: WebSocket, who: SocketAddr) { // send a ping (unsupported by some browsers) just to kick things off and get a response - if socket.send(Message::Ping(vec![1, 2, 3].into())).await.is_ok() { + if socket + .send(Message::Ping(vec![1, 2, 3].into())) + .await + .is_ok() + { println!("Pinged {who}..."); } else { println!("Could not send ping {who}!");