Skip to content

Commit

Permalink
Merge pull request #76 from hubertshelley/dependabot/cargo/tokio-tung…
Browse files Browse the repository at this point in the history
…stenite-0.26.1

chore(deps): update tokio-tungstenite requirement from 0.25.0 to 0.26.1
  • Loading branch information
hubertshelley authored Dec 20, 2024
2 parents 8fd17dd + 20b6244 commit 9bb949a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/websocket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
async-trait = "0.1.83"
silent = { path = "../../silent", features = ["upgrade"] }
tokio = { version = "1.41.0", features = ["full"] }
tokio-tungstenite = "0.25.0"
tokio-tungstenite = "0.26.1"
futures-util = "0.3.31"
backtrace = "0.3.74"
headers = "0.4.0"
2 changes: 1 addition & 1 deletion silent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ serde_html_form = "0.2.6"
mime = "0.3.17"
futures-util = "0.3.31"
chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
tokio-tungstenite = { version = "0.25.0", optional = true }
tokio-tungstenite = { version = "0.26.1", optional = true }
headers = "0.4.0"
tokio-stream = { version = "0.1.16", features = ["net"], optional = true }
pin-project = { version = "1.1", optional = true }
Expand Down
29 changes: 14 additions & 15 deletions silent/src/ws/message.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{Result, SilentError};
use std::borrow::Cow;
use bytes::Bytes;
use std::fmt;
use std::fmt::Formatter;
use std::ops::Deref;
use tokio_tungstenite::tungstenite::protocol;
use tokio_tungstenite::tungstenite::protocol::frame::{Payload, Utf8Payload};
use tokio_tungstenite::tungstenite::{protocol, Utf8Bytes};

#[derive(Eq, PartialEq, Clone)]
pub struct Message {
Expand All @@ -22,31 +21,31 @@ impl Deref for Message {
impl Message {
/// Construct a new Text `Message`.
#[inline]
pub fn text<S: Into<Utf8Payload>>(s: S) -> Message {
pub fn text<S: Into<Utf8Bytes>>(s: S) -> Message {
Message {
inner: protocol::Message::text(s),
}
}

/// Construct a new Binary `Message`.
#[inline]
pub fn binary<V: Into<Payload>>(v: V) -> Message {
pub fn binary<V: Into<Bytes>>(v: V) -> Message {
Message {
inner: protocol::Message::binary(v.into()),
inner: protocol::Message::binary(v),
}
}

/// Construct a new Ping `Message`.
#[inline]
pub fn ping<V: Into<Payload>>(v: V) -> Message {
pub fn ping<V: Into<Bytes>>(v: V) -> Message {
Message {
inner: protocol::Message::Ping(v.into()),
}
}

/// Construct a new pong `Message`.
#[inline]
pub fn pong<V: Into<Payload>>(v: V) -> Message {
pub fn pong<V: Into<Bytes>>(v: V) -> Message {
Message {
inner: protocol::Message::Pong(v.into()),
}
Expand All @@ -62,11 +61,11 @@ impl Message {

/// Construct a Close `Message` with a code and reason.
#[inline]
pub fn close_with(code: impl Into<u16>, reason: impl Into<Cow<'static, str>>) -> Message {
pub fn close_with(code: impl Into<u16>, reason: impl Into<String>) -> Message {
Message {
inner: protocol::Message::Close(Some(protocol::frame::CloseFrame {
code: protocol::frame::coding::CloseCode::from(code.into()),
reason: reason.into(),
reason: reason.into().into(),
})),
}
}
Expand Down Expand Up @@ -123,10 +122,10 @@ impl Message {
#[inline]
pub fn as_bytes(&self) -> &[u8] {
match self.inner {
protocol::Message::Text(ref s) => s.as_slice(),
protocol::Message::Binary(ref v) => v.as_slice(),
protocol::Message::Ping(ref v) => v.as_slice(),
protocol::Message::Pong(ref v) => v.as_slice(),
protocol::Message::Text(ref s) => s.as_bytes(),
protocol::Message::Binary(ref v) => v.iter().as_slice(),
protocol::Message::Ping(ref v) => v.iter().as_slice(),
protocol::Message::Pong(ref v) => v.iter().as_slice(),
protocol::Message::Close(_) => &[],
protocol::Message::Frame(ref v) => v.payload(),
}
Expand All @@ -135,7 +134,7 @@ impl Message {
/// Destructure this message into binary data.
#[inline]
pub fn into_bytes(self) -> Vec<u8> {
self.inner.into_data().as_slice().to_vec()
self.inner.into_data().to_vec()
}
}

Expand Down

0 comments on commit 9bb949a

Please sign in to comment.