Skip to content

Commit

Permalink
switch CI and rustfmt to stable
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraef committed Jun 9, 2024
1 parent 8a6890c commit 5f25aed
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 119 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- fix-ci
pull_request:

jobs:
Expand All @@ -12,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
toolchain: [ nightly ]
toolchain: [ stable ]
runs-on: ${{ matrix.os }}
steps:

Expand Down
12 changes: 2 additions & 10 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down
18 changes: 10 additions & 8 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -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"

40 changes: 7 additions & 33 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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.
}
Expand Down Expand Up @@ -313,19 +296,10 @@ impl Sink<Message> 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!";
Expand Down
24 changes: 6 additions & 18 deletions src/native.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand Down Expand Up @@ -149,8 +140,7 @@ impl WebSocketResponse {
}
.into());
}
}
else {
} else {
tracing::debug!("missing Connection header");
return Err(HandshakeError::MissingHeader {
header: reqwest::header::CONNECTION,
Expand All @@ -171,8 +161,7 @@ impl WebSocketResponse {
}
.into());
}
}
else {
} else {
tracing::debug!("missing Upgrade header");
return Err(HandshakeError::MissingHeader {
header: reqwest::header::UPGRADE,
Expand All @@ -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,
Expand Down
10 changes: 2 additions & 8 deletions src/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#[cfg(feature = "json")]
use serde::{
de::DeserializeOwned,
Serialize,
};
use serde::{de::DeserializeOwned, Serialize};

#[cfg(feature = "json")]
use crate::Error;
Expand Down Expand Up @@ -247,11 +244,8 @@ impl From<u16> for CloseCode {
#[cfg(test)]
#[cfg(feature = "json")]
mod test {
use serde::{
Deserialize,
Serialize,
};
use crate::Error;
use serde::{Deserialize, Serialize};

use crate::Message;

Expand Down
52 changes: 11 additions & 41 deletions src/wasm.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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::<JsString>() {
} else if let Ok(text) = event.data().dyn_into::<JsString>() {
let _ = tx.send(Some(Ok(Message::Text(text.into()))));
}
else {
} else {
tracing::debug!(event = ?event.data(), "received unknown message event");
}
})
Expand All @@ -154,8 +125,7 @@ impl WebSysWebSocketStream {
Ok(()) => return,
Err(error) => error,
}
}
else {
} else {
error
};

Expand Down

0 comments on commit 5f25aed

Please sign in to comment.