Skip to content

Commit

Permalink
Add From impls for extract::ws::Message (#1421)
Browse files Browse the repository at this point in the history
* Add From impls for extract::ws::Message

These come from tungstenite but were not exposed by axum

* Add changelog entry
  • Loading branch information
Rapptz committed Sep 26, 2022
1 parent 5a11ae8 commit fef95bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions axum/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
you likely need to re-enable the `tokio` feature ([#1382])
- **breaking:** `handler::{WithState, IntoService}` are merged into one type,
named `HandlerService` ([#1418])
- **added:** String and binary `From` impls have been added to `extract::ws::Message`
to be more inline with `tungstenite` ([#1421])

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

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

Expand Down
24 changes: 24 additions & 0 deletions axum/src/extract/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,30 @@ impl Message {
}
}

impl From<String> for Message {
fn from(string: String) -> Self {
Message::Text(string)
}
}

impl<'s> From<&'s str> for Message {
fn from(string: &'s str) -> Self {
Message::Text(string.into())
}
}

impl<'b> From<&'b [u8]> for Message {
fn from(data: &'b [u8]) -> Self {
Message::Binary(data.into())
}
}

impl From<Vec<u8>> for Message {
fn from(data: Vec<u8>) -> Self {
Message::Binary(data)
}
}

impl From<Message> for Vec<u8> {
fn from(msg: Message) -> Self {
msg.into_data()
Expand Down

0 comments on commit fef95bf

Please sign in to comment.