diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index 7483c6c3..2589459b 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -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 @@ -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) diff --git a/axum/src/extract/ws.rs b/axum/src/extract/ws.rs index 4156a16c..a48f9a73 100644 --- a/axum/src/extract/ws.rs +++ b/axum/src/extract/ws.rs @@ -545,6 +545,30 @@ impl Message { } } +impl From 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> for Message { + fn from(data: Vec) -> Self { + Message::Binary(data) + } +} + impl From for Vec { fn from(msg: Message) -> Self { msg.into_data()