From fe910986b70b3cd5f1890420c8a6fa0371b33d31 Mon Sep 17 00:00:00 2001 From: Andrei Volykhin Date: Tue, 18 Nov 2025 15:32:53 +0300 Subject: [PATCH] Return an empty slice on safe slice casting error The cargo `byte-slice-cast` crate supports safe `u8 -> f32` slice casting through the `as_slice_of` trait function. However, for dynamic linked crate from rust toolchain (`byte-slice-cast-0.2.0`) in case if source `u8` slice is empty, the `WrongAlignment` error will be returned, so need to handle this edge case properly and return the empty `f32` slice on error. Please notice that the newest version (`byte-slice-cast-1.2.3`) is handling this case without alignment error (return an empty slice). https://docs.rs/byte-slice-cast/0.2.0/src/byte_slice_cast/lib.rs.html#206 https://docs.rs/byte-slice-cast/1.2.3/src/byte_slice_cast/lib.rs.html#263 Signed-off-by: Andrei Volykhin --- backends/gstreamer/player.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backends/gstreamer/player.rs b/backends/gstreamer/player.rs index df310f6e..53a8aa78 100644 --- a/backends/gstreamer/player.rs +++ b/backends/gstreamer/player.rs @@ -100,7 +100,7 @@ fn metadata_from_media_info(media_info: &gst_play::PlayMediaInfo) -> Result); impl AsRef<[f32]> for GStreamerAudioChunk { fn as_ref(&self) -> &[f32] { - self.0.as_ref().as_slice_of::().unwrap() + self.0.as_ref().as_slice_of::().unwrap_or_default() } }