Skip to content

Commit

Permalink
Bump tokio-tungstenite to 0.26
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Jan 24, 2025
1 parent 12a8d4a commit 97c9f79
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ url = { version = "2.5", default-features = false }
tokio = { version = "1", features = ["net", "time"] }
tokio-rustls = { version = "0.26", default-features = false, features = ["ring", "tls12"] } # Required to enable the necessary features for tokio-tungstenite
tokio-socks = { version = "0.5", optional = true }
tokio-tungstenite = { version = "0.24", features = ["rustls-tls-webpki-roots"] }
tokio-tungstenite = { version = "0.26", features = ["rustls-tls-webpki-roots"] }

# TOR deps
arti-client = { version = "0.26", default-features = false, features = ["onion-service-client", "rustls", "static-sqlite", "tokio"], optional = true }
Expand Down
29 changes: 13 additions & 16 deletions src/message.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) 2022-2024 Yuki Kishimoto
// Distributed under the MIT software license

#[cfg(not(target_arch = "wasm32"))]
use std::borrow::Cow;

#[cfg(not(target_arch = "wasm32"))]
use tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode;
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -72,11 +69,11 @@ pub enum Message {
// }

#[cfg(not(target_arch = "wasm32"))]
impl From<CloseFrame> for TungsteniteCloseFrame<'_> {
impl From<CloseFrame> for TungsteniteCloseFrame {
fn from(frame: CloseFrame) -> Self {
Self {
code: CloseCode::from(frame.code),
reason: Cow::Owned(frame.reason),
reason: frame.reason.into(),
}
}
}
Expand All @@ -85,21 +82,21 @@ impl From<CloseFrame> for TungsteniteCloseFrame<'_> {
impl From<Message> for TungsteniteMessage {
fn from(msg: Message) -> Self {
match msg {
Message::Text(text) => Self::Text(text),
Message::Binary(data) => Self::Binary(data),
Message::Ping(data) => Self::Ping(data),
Message::Pong(data) => Self::Pong(data),
Message::Text(text) => Self::Text(text.into()),
Message::Binary(data) => Self::Binary(data.into()),
Message::Ping(data) => Self::Ping(data.into()),
Message::Pong(data) => Self::Pong(data.into()),
Message::Close(frame) => Self::Close(frame.map(|f| f.into())),
}
}
}

#[cfg(not(target_arch = "wasm32"))]
impl From<TungsteniteCloseFrame<'_>> for CloseFrame {
fn from(frame: TungsteniteCloseFrame<'_>) -> Self {
impl From<TungsteniteCloseFrame> for CloseFrame {
fn from(frame: TungsteniteCloseFrame) -> Self {
Self {
code: frame.code.into(),
reason: frame.reason.into_owned(),
reason: frame.reason.to_string(),
}
}
}
Expand All @@ -108,10 +105,10 @@ impl From<TungsteniteCloseFrame<'_>> for CloseFrame {
impl From<TungsteniteMessage> for Message {
fn from(msg: TungsteniteMessage) -> Self {
match msg {
TungsteniteMessage::Text(text) => Self::Text(text),
TungsteniteMessage::Binary(data) => Self::Binary(data),
TungsteniteMessage::Ping(data) => Self::Ping(data),
TungsteniteMessage::Pong(data) => Self::Pong(data),
TungsteniteMessage::Text(text) => Self::Text(text.to_string()),
TungsteniteMessage::Binary(data) => Self::Binary(data.to_vec()),
TungsteniteMessage::Ping(data) => Self::Ping(data.to_vec()),
TungsteniteMessage::Pong(data) => Self::Pong(data.to_vec()),
TungsteniteMessage::Close(frame) => Self::Close(frame.map(|f| f.into())),
// SAFETY: from tungstenite docs: "you're not going to get this value while reading the message".
// SAFETY: this conversion is used only in Stream trait, so when reading the messages.
Expand Down

0 comments on commit 97c9f79

Please sign in to comment.