diff --git a/src/futures.rs b/src/futures.rs index 8100f7e..ee941d5 100644 --- a/src/futures.rs +++ b/src/futures.rs @@ -5,7 +5,7 @@ use futures_core::Stream; use crate::{SendWrapper, invalid_deref, invalid_poll}; -impl Future for SendWrapper { +impl Future for SendWrapper { type Output = F::Output; /// Polls this [`SendWrapper`] [`Future`]. @@ -22,7 +22,7 @@ impl Future for SendWrapper { } } -impl Stream for SendWrapper { +impl Stream for SendWrapper { type Item = S::Item; /// Polls this [`SendWrapper`] [`Stream`]. diff --git a/src/lib.rs b/src/lib.rs index 4bbd63e..d489c00 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -122,9 +122,9 @@ cfg_if::cfg_if! { /// threads, as long as you access the contained value only from within the /// original thread and make sure that it is dropped from within the original /// thread. -pub struct SendWrapper { - data: ManuallyDrop, +pub struct SendWrapper { thread_id: ThreadId, + data: ManuallyDrop, } impl SendWrapper { @@ -138,13 +138,6 @@ impl SendWrapper { } } - /// Returns `true` if the value can be safely accessed from within the - /// current thread. - #[inline] - pub fn valid(&self) -> bool { - self.thread_id == current_id() - } - /// Takes the value out of the `SendWrapper`. /// /// # Safety @@ -178,6 +171,15 @@ impl SendWrapper { invalid_deref() } } +} + +impl SendWrapper { + /// Returns `true` if the value can be safely accessed from within the + /// current thread. + #[inline] + pub fn valid(&self) -> bool { + self.thread_id == current_id() + } /// Returns a reference to the contained value. /// @@ -270,10 +272,10 @@ impl SendWrapper { } } -unsafe impl Send for SendWrapper {} -unsafe impl Sync for SendWrapper {} +unsafe impl Send for SendWrapper {} +unsafe impl Sync for SendWrapper {} -impl Drop for SendWrapper { +impl Drop for SendWrapper { /// Drops the contained value. /// /// # Panics @@ -309,7 +311,7 @@ impl Drop for SendWrapper { } } -impl fmt::Debug for SendWrapper { +impl fmt::Debug for SendWrapper { /// Formats the value using the given formatter. /// /// If the `SendWrapper` is formatted from a different thread than the @@ -319,7 +321,7 @@ impl fmt::Debug for SendWrapper { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut f = f.debug_struct("SendWrapper"); if let Some(data) = self.get() { - f.field("data", data); + f.field("data", &data); } else { f.field("data", &""); }