Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
adryzz committed Dec 16, 2024
1 parent c1a30ed commit b33665d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
19 changes: 11 additions & 8 deletions axum/src/extract/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -677,9 +681,11 @@ impl Message {
pub fn into_text(self) -> Result<String, Error> {
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()),
}
Expand Down Expand Up @@ -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()));
}
}
5 changes: 1 addition & 4 deletions examples/testing-websockets/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions examples/websockets/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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!");

Expand Down
6 changes: 5 additions & 1 deletion examples/websockets/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}!");
Expand Down

0 comments on commit b33665d

Please sign in to comment.