diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 82412b8..4f01cde 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -4,6 +4,7 @@ on: push: branches: - main + - fix-ci pull_request: jobs: @@ -12,7 +13,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest, windows-latest, macos-latest ] - toolchain: [ nightly ] + toolchain: [ stable ] runs-on: ${{ matrix.os }} steps: diff --git a/examples/hello_world.rs b/examples/hello_world.rs index c91e41a..c82604e 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,14 +1,6 @@ -use futures_util::{ - SinkExt, - StreamExt, - TryStreamExt, -}; +use futures_util::{SinkExt, StreamExt, TryStreamExt}; use reqwest::Client; -use reqwest_websocket::{ - Error, - Message, - RequestBuilderExt, -}; +use reqwest_websocket::{Error, Message, RequestBuilderExt}; #[tokio::main] async fn main() -> Result<(), Error> { diff --git a/rustfmt.toml b/rustfmt.toml index 1ccbb88..4938acd 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,10 +1,12 @@ -unstable_features = true reorder_imports = true -group_imports = "StdExternalCrate" -force_multiline_blocks = true -format_code_in_doc_comments = true -imports_granularity = "Crate" -wrap_comments = true -control_brace_style = "ClosingNextLine" -imports_layout = "Vertical" + +# only available with nightly :( +#unstable_features = true +#force_multiline_blocks = true +#group_imports = "StdExternalCrate" +#format_code_in_doc_comments = true +#imports_granularity = "Crate" +#wrap_comments = true +#control_brace_style = "ClosingNextLine" +#imports_layout = "Vertical" diff --git a/src/lib.rs b/src/lib.rs index 7e6a804..09eb5ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,31 +53,15 @@ mod wasm; use std::{ pin::Pin, - task::{ - Context, - Poll, - }, + task::{Context, Poll}, }; -use futures_util::{ - Sink, - SinkExt, - Stream, - StreamExt, -}; +use futures_util::{Sink, SinkExt, Stream, StreamExt}; #[cfg(not(target_arch = "wasm32"))] #[cfg_attr(docsrs, doc(cfg(not(target_arch = "wasm32"))))] pub use native::HandshakeError; -pub use protocol::{ - CloseCode, - Message, -}; -use reqwest::{ - Client, - ClientBuilder, - IntoUrl, - RequestBuilder, -}; +pub use protocol::{CloseCode, Message}; +use reqwest::{Client, ClientBuilder, IntoUrl, RequestBuilder}; /// Errors returned by `reqwest_websocket`. #[derive(Debug, thiserror::Error)] @@ -280,8 +264,7 @@ impl Stream for WebSocket { Poll::Ready(Some(Ok(message))) => { if let Ok(message) = message.try_into() { return Poll::Ready(Some(Ok(message))); - } - else { + } else { // This won't convert pings, pongs, etc. but we // don't care about those. } @@ -313,19 +296,10 @@ impl Sink for WebSocket { #[cfg(test)] mod tests { - use futures_util::{ - SinkExt, - TryStreamExt, - }; + use futures_util::{SinkExt, TryStreamExt}; use reqwest::Client; - use super::{ - websocket, - CloseCode, - Message, - RequestBuilderExt, - WebSocket, - }; + use super::{websocket, CloseCode, Message, RequestBuilderExt, WebSocket}; async fn test_websocket(mut websocket: WebSocket) { let text = "Hello, World!"; diff --git a/src/native.rs b/src/native.rs index c205e4a..22b1639 100644 --- a/src/native.rs +++ b/src/native.rs @@ -1,21 +1,12 @@ use std::borrow::Cow; use reqwest::{ - header::{ - HeaderName, - HeaderValue, - }, - RequestBuilder, - Response, - StatusCode, - Version, + header::{HeaderName, HeaderValue}, + RequestBuilder, Response, StatusCode, Version, }; use crate::{ - protocol::{ - CloseCode, - Message, - }, + protocol::{CloseCode, Message}, Error, }; @@ -149,8 +140,7 @@ impl WebSocketResponse { } .into()); } - } - else { + } else { tracing::debug!("missing Connection header"); return Err(HandshakeError::MissingHeader { header: reqwest::header::CONNECTION, @@ -171,8 +161,7 @@ impl WebSocketResponse { } .into()); } - } - else { + } else { tracing::debug!("missing Upgrade header"); return Err(HandshakeError::MissingHeader { header: reqwest::header::UPGRADE, @@ -195,8 +184,7 @@ impl WebSocketResponse { } .into()); } - } - else { + } else { tracing::debug!("missing Sec-Websocket-Accept header"); return Err(HandshakeError::MissingHeader { header: reqwest::header::SEC_WEBSOCKET_ACCEPT, diff --git a/src/protocol.rs b/src/protocol.rs index b35e98c..6fbcdac 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -1,8 +1,5 @@ #[cfg(feature = "json")] -use serde::{ - de::DeserializeOwned, - Serialize, -}; +use serde::{de::DeserializeOwned, Serialize}; #[cfg(feature = "json")] use crate::Error; @@ -247,11 +244,8 @@ impl From for CloseCode { #[cfg(test)] #[cfg(feature = "json")] mod test { - use serde::{ - Deserialize, - Serialize, - }; use crate::Error; + use serde::{Deserialize, Serialize}; use crate::Message; diff --git a/src/wasm.rs b/src/wasm.rs index 31d19b8..b5c1e86 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -1,45 +1,18 @@ use std::{ pin::Pin, - task::{ - Context, - Poll, - }, + task::{Context, Poll}, }; -use futures_util::{ - Sink, - Stream, -}; -use reqwest::{ - Request, - Url, -}; -use tokio::sync::{ - mpsc, - oneshot, -}; +use futures_util::{Sink, Stream}; +use reqwest::{Request, Url}; +use tokio::sync::{mpsc, oneshot}; use web_sys::{ - js_sys::{ - Array, - ArrayBuffer, - JsString, - Uint8Array, - }, - wasm_bindgen::{ - closure::Closure, - JsCast, - JsValue, - }, - CloseEvent, - ErrorEvent, - Event, - MessageEvent, + js_sys::{Array, ArrayBuffer, JsString, Uint8Array}, + wasm_bindgen::{closure::Closure, JsCast, JsValue}, + CloseEvent, ErrorEvent, Event, MessageEvent, }; -use crate::protocol::{ - CloseCode, - Message, -}; +use crate::protocol::{CloseCode, Message}; #[derive(Debug, thiserror::Error)] pub enum WebSysError { @@ -128,11 +101,9 @@ impl WebSysWebSocketStream { let array = Uint8Array::new(&abuf); let data = array.to_vec(); let _ = tx.send(Some(Ok(Message::Binary(data)))); - } - else if let Ok(text) = event.data().dyn_into::() { + } else if let Ok(text) = event.data().dyn_into::() { let _ = tx.send(Some(Ok(Message::Text(text.into())))); - } - else { + } else { tracing::debug!(event = ?event.data(), "received unknown message event"); } }) @@ -154,8 +125,7 @@ impl WebSysWebSocketStream { Ok(()) => return, Err(error) => error, } - } - else { + } else { error };