Skip to content

Commit fef95bf

Browse files
authored
Add From impls for extract::ws::Message (#1421)
* Add From impls for extract::ws::Message These come from tungstenite but were not exposed by axum * Add changelog entry
1 parent 5a11ae8 commit fef95bf

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

axum/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4040
you likely need to re-enable the `tokio` feature ([#1382])
4141
- **breaking:** `handler::{WithState, IntoService}` are merged into one type,
4242
named `HandlerService` ([#1418])
43+
- **added:** String and binary `From` impls have been added to `extract::ws::Message`
44+
to be more inline with `tungstenite` ([#1421])
4345

4446
[#1368]: https://github.com/tokio-rs/axum/pull/1368
4547
[#1371]: https://github.com/tokio-rs/axum/pull/1371
@@ -52,6 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5254
[#1408]: https://github.com/tokio-rs/axum/pull/1408
5355
[#1414]: https://github.com/tokio-rs/axum/pull/1414
5456
[#1418]: https://github.com/tokio-rs/axum/pull/1418
57+
[#1421]: https://github.com/tokio-rs/axum/pull/1421
5558

5659
# 0.6.0-rc.2 (10. September, 2022)
5760

axum/src/extract/ws.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,30 @@ impl Message {
545545
}
546546
}
547547

548+
impl From<String> for Message {
549+
fn from(string: String) -> Self {
550+
Message::Text(string)
551+
}
552+
}
553+
554+
impl<'s> From<&'s str> for Message {
555+
fn from(string: &'s str) -> Self {
556+
Message::Text(string.into())
557+
}
558+
}
559+
560+
impl<'b> From<&'b [u8]> for Message {
561+
fn from(data: &'b [u8]) -> Self {
562+
Message::Binary(data.into())
563+
}
564+
}
565+
566+
impl From<Vec<u8>> for Message {
567+
fn from(data: Vec<u8>) -> Self {
568+
Message::Binary(data)
569+
}
570+
}
571+
548572
impl From<Message> for Vec<u8> {
549573
fn from(msg: Message) -> Self {
550574
msg.into_data()

0 commit comments

Comments
 (0)