use core::borrow::{Borrow, BorrowMut};
#[cfg(any(
feature = "portable-atomic",
target_has_atomic = "ptr",
has_atomic_load_store
))]
use crate::spsc;
#[cfg(any(
feature = "portable-atomic",
all(feature = "mpmc_large", target_has_atomic = "ptr"),
all(not(feature = "mpmc_large"), target_has_atomic = "8")
))]
use crate::mpmc;
pub(crate) trait SealedStorage {
type Buffer<T>: ?Sized + Borrow<[T]> + BorrowMut<[T]>;
#[allow(unused)]
fn len<T>(this: *const Self::Buffer<T>) -> usize;
#[allow(unused)]
fn as_ptr<T>(this: *mut Self::Buffer<T>) -> *mut T;
#[cfg(any(
feature = "portable-atomic",
all(feature = "mpmc_large", target_has_atomic = "ptr"),
all(not(feature = "mpmc_large"), target_has_atomic = "8")
))]
fn as_mpmc_view<T>(this: &mpmc::QueueInner<T, Self>) -> &mpmc::QueueView<T>
where
Self: Storage + Sized;
#[cfg(any(
feature = "portable-atomic",
all(feature = "mpmc_large", target_has_atomic = "ptr"),
all(not(feature = "mpmc_large"), target_has_atomic = "8")
))]
fn as_mpmc_mut_view<T>(this: &mut mpmc::QueueInner<T, Self>) -> &mut mpmc::QueueView<T>
where
Self: Storage + Sized;
#[cfg(any(
feature = "portable-atomic",
target_has_atomic = "ptr",
has_atomic_load_store
))]
fn as_queue_view<T>(this: &spsc::QueueInner<T, Self>) -> &spsc::QueueView<T>
where
Self: Storage + Sized;
#[cfg(any(
feature = "portable-atomic",
target_has_atomic = "ptr",
has_atomic_load_store
))]
fn as_mut_queue_view<T>(this: &mut spsc::QueueInner<T, Self>) -> &mut spsc::QueueView<T>
where
Self: Storage + Sized;
}
#[allow(private_bounds)]
pub trait Storage: SealedStorage {}
pub enum OwnedStorage<const N: usize> {}
impl<const N: usize> Storage for OwnedStorage<N> {}
impl<const N: usize> SealedStorage for OwnedStorage<N> {
type Buffer<T> = [T; N];
fn len<T>(_: *const Self::Buffer<T>) -> usize {
N
}
fn as_ptr<T>(this: *mut Self::Buffer<T>) -> *mut T {
this.cast()
}
#[cfg(any(
feature = "portable-atomic",
all(feature = "mpmc_large", target_has_atomic = "ptr"),
all(not(feature = "mpmc_large"), target_has_atomic = "8")
))]
fn as_mpmc_view<T>(this: &mpmc::Queue<T, N>) -> &mpmc::QueueView<T>
where
Self: Storage + Sized,
{
this.as_view_private()
}
#[cfg(any(
feature = "portable-atomic",
all(feature = "mpmc_large", target_has_atomic = "ptr"),
all(not(feature = "mpmc_large"), target_has_atomic = "8")
))]
fn as_mpmc_mut_view<T>(this: &mut mpmc::Queue<T, N>) -> &mut mpmc::QueueView<T>
where
Self: Storage + Sized,
{
this.as_view_mut_private()
}
#[cfg(any(
feature = "portable-atomic",
target_has_atomic = "ptr",
has_atomic_load_store
))]
fn as_queue_view<T>(this: &spsc::QueueInner<T, Self>) -> &spsc::QueueView<T>
where
Self: Storage + Sized,
{
this.as_view_private()
}
#[cfg(any(
feature = "portable-atomic",
target_has_atomic = "ptr",
has_atomic_load_store
))]
fn as_mut_queue_view<T>(this: &mut spsc::QueueInner<T, Self>) -> &mut spsc::QueueView<T>
where
Self: Storage + Sized,
{
this.as_mut_view_private()
}
}
pub enum ViewStorage {}
impl Storage for ViewStorage {}
impl SealedStorage for ViewStorage {
type Buffer<T> = [T];
fn len<T>(this: *const Self::Buffer<T>) -> usize {
this.len()
}
fn as_ptr<T>(this: *mut Self::Buffer<T>) -> *mut T {
this.cast()
}
#[cfg(any(
feature = "portable-atomic",
all(feature = "mpmc_large", target_has_atomic = "ptr"),
all(not(feature = "mpmc_large"), target_has_atomic = "8")
))]
fn as_mpmc_view<T>(this: &mpmc::QueueInner<T, Self>) -> &mpmc::QueueView<T>
where
Self: Storage + Sized,
{
this
}
#[cfg(any(
feature = "portable-atomic",
all(feature = "mpmc_large", target_has_atomic = "ptr"),
all(not(feature = "mpmc_large"), target_has_atomic = "8")
))]
fn as_mpmc_mut_view<T>(this: &mut mpmc::QueueInner<T, Self>) -> &mut mpmc::QueueView<T>
where
Self: Storage + Sized,
{
this
}
#[cfg(any(
feature = "portable-atomic",
target_has_atomic = "ptr",
has_atomic_load_store
))]
fn as_queue_view<T>(this: &spsc::QueueInner<T, Self>) -> &spsc::QueueView<T>
where
Self: Storage + Sized,
{
this
}
#[cfg(any(
feature = "portable-atomic",
target_has_atomic = "ptr",
has_atomic_load_store
))]
fn as_mut_queue_view<T>(this: &mut spsc::QueueInner<T, Self>) -> &mut spsc::QueueView<T>
where
Self: Storage + Sized,
{
this
}
}