From c997137383076296246cab3e402f3a713e04feb0 Mon Sep 17 00:00:00 2001 From: Andrei Nesterov Date: Mon, 17 Mar 2025 17:15:15 +0300 Subject: [PATCH] Implement `From` for `Message` (#3273) --- axum/CHANGELOG.md | 6 ++++++ axum/src/extract/ws.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index 9749052f..ad23b447 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# Unreleased + +- **added:** Implement `From` for `Message` ([#3273]) + +[#3273]: https://github.com/tokio-rs/axum/pull/3273 + # 0.8.2 - **added:** Implement `OptionalFromRequest` for `Json` ([#3142]) diff --git a/axum/src/extract/ws.rs b/axum/src/extract/ws.rs index 08dbe204..2f367e43 100644 --- a/axum/src/extract/ws.rs +++ b/axum/src/extract/ws.rs @@ -858,6 +858,12 @@ impl<'b> From<&'b [u8]> for Message { } } +impl From for Message { + fn from(data: Bytes) -> Self { + Message::Binary(data) + } +} + impl From> for Message { fn from(data: Vec) -> Self { Message::Binary(data.into())