Skip to content
Closed
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
23 changes: 23 additions & 0 deletions src/platform/maybe_send.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! The following zero-sized type is for applying [`Send`]/[`Sync`]` restrictions to ensure
//! consistent behaviour across different platforms. The verbosely named type is used
//! (rather than using the markers directly) in the hope of making the compile errors
//! slightly more helpful.

// TODO: Remove this in favour of using negative trait bounds if they stabilise.

/// A marker used to remove the `Send` and `Sync` traits.
pub(crate) struct NotSendSyncAcrossAllPlatforms(std::marker::PhantomData<*mut ()>);

impl Default for NotSendSyncAcrossAllPlatforms {
fn default() -> Self {
NotSendSyncAcrossAllPlatforms(std::marker::PhantomData)
}
}

// TODO: Implement Send on platforms which support it.

#[cfg(any(
// Windows with WASAPI allows for a Send Stream
all(windows, not(feature = "asio")),
))]
unsafe impl Send for NotSendSyncAcrossAllPlatforms {}
20 changes: 4 additions & 16 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
//! type and its associated [`Device`], [`Stream`] and other associated types. These
//! types are useful in the case that users require switching between audio host APIs at runtime.

mod maybe_send;

pub(crate) use maybe_send::*;

#[doc(inline)]
pub use self::platform_impl::*;

Expand Down Expand Up @@ -724,19 +728,3 @@ mod platform_impl {
.into()
}
}

// The following zero-sized types are for applying Send/Sync restrictions to ensure
// consistent behaviour across different platforms. These verbosely named types are used
// (rather than using the markers directly) in the hope of making the compile errors
// slightly more helpful.
//
// TODO: Remove these in favour of using negative trait bounds if they stabilise.

// A marker used to remove the `Send` and `Sync` traits.
struct NotSendSyncAcrossAllPlatforms(std::marker::PhantomData<*mut ()>);

impl Default for NotSendSyncAcrossAllPlatforms {
fn default() -> Self {
NotSendSyncAcrossAllPlatforms(std::marker::PhantomData)
}
}