From b6aeab28802b87c42063b29eb40b51dde560967c Mon Sep 17 00:00:00 2001 From: noakodaren <94870395+noakodaren@users.noreply.github.com> Date: Wed, 23 Oct 2024 12:27:16 +0200 Subject: [PATCH] make transmutes sound by adding repr(C) fixes an issue similar to https://github.com/fereidani/kanal/issues/36 --- src/oneshot.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/oneshot.rs b/src/oneshot.rs index 09cff47..133ab77 100644 --- a/src/oneshot.rs +++ b/src/oneshot.rs @@ -246,6 +246,7 @@ fn try_drop_internal(internal_ptr: OneshotInternalPointer) -> bool { /// Note: sending a message in Kanal one-shot algorithm can be /// blocking/suspending if the sender reaches the `send` function before /// receiver calling the recv. +#[repr(C)] pub struct OneshotSender { internal_ptr: OneshotInternalPointer, } @@ -360,6 +361,7 @@ impl OneshotSender { /// achievable with [`Self::send`] which returns a future that should be polled /// until transfer is done. #[cfg(feature = "async")] +#[repr(C)] pub struct OneshotAsyncSender { internal_ptr: OneshotInternalPointer, } @@ -380,6 +382,7 @@ impl Drop for OneshotAsyncSender { /// receive a single message. It can be converted to async /// [`OneshotAsyncReceiver`] by calling [`Self::to_async`]. Receiving a /// message is achievable with [`Self::recv`]. +#[repr(C)] pub struct OneshotReceiver { internal_ptr: OneshotInternalPointer, } @@ -486,6 +489,7 @@ impl OneshotReceiver { /// achievable with [`Self::recv`] which returns a future that should be polled /// to receive the message. #[cfg(feature = "async")] +#[repr(C)] pub struct OneshotAsyncReceiver { internal_ptr: OneshotInternalPointer, }