Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use futures_core::Stream;

use crate::{SendWrapper, invalid_deref, invalid_poll};

impl<F: Future> Future for SendWrapper<F> {
impl<F: Future + ?Sized> Future for SendWrapper<F> {
type Output = F::Output;

/// Polls this [`SendWrapper`] [`Future`].
Expand All @@ -22,7 +22,7 @@ impl<F: Future> Future for SendWrapper<F> {
}
}

impl<S: Stream> Stream for SendWrapper<S> {
impl<S: Stream + ?Sized> Stream for SendWrapper<S> {
type Item = S::Item;

/// Polls this [`SendWrapper`] [`Stream`].
Expand Down
30 changes: 16 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
data: ManuallyDrop<T>,
pub struct SendWrapper<T: ?Sized> {
thread_id: ThreadId,
data: ManuallyDrop<T>,
}

impl<T> SendWrapper<T> {
Expand All @@ -138,13 +138,6 @@ impl<T> SendWrapper<T> {
}
}

/// 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<T>`.
///
/// # Safety
Expand Down Expand Up @@ -178,6 +171,15 @@ impl<T> SendWrapper<T> {
invalid_deref()
}
}
}

impl<T: ?Sized> SendWrapper<T> {
/// 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.
///
Expand Down Expand Up @@ -270,10 +272,10 @@ impl<T> SendWrapper<T> {
}
}

unsafe impl<T> Send for SendWrapper<T> {}
unsafe impl<T> Sync for SendWrapper<T> {}
unsafe impl<T: ?Sized> Send for SendWrapper<T> {}
unsafe impl<T: ?Sized> Sync for SendWrapper<T> {}

impl<T> Drop for SendWrapper<T> {
impl<T: ?Sized> Drop for SendWrapper<T> {
/// Drops the contained value.
///
/// # Panics
Expand Down Expand Up @@ -309,7 +311,7 @@ impl<T> Drop for SendWrapper<T> {
}
}

impl<T: fmt::Debug> fmt::Debug for SendWrapper<T> {
impl<T: fmt::Debug + ?Sized> fmt::Debug for SendWrapper<T> {
/// Formats the value using the given formatter.
///
/// If the `SendWrapper<T>` is formatted from a different thread than the
Expand All @@ -319,7 +321,7 @@ impl<T: fmt::Debug> fmt::Debug for SendWrapper<T> {
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", &"<invalid>");
}
Expand Down