use crate::flavor::Flavor;
use crate::flavor::{FlavorImpl, FlavorNew, FlavorSelect, Queue, Token};
use crate::shared::ChannelShared;
use crate::SenderType;
use core::mem::MaybeUninit;
use std::sync::Arc;
pub struct Null();
impl Queue for Null {
type Item = ();
#[inline(always)]
fn pop(&self) -> Option<()> {
None
}
#[inline(always)]
fn push(&self, _item: ()) -> Result<(), ()> {
unreachable!();
}
#[inline(always)]
fn len(&self) -> usize {
0
}
#[inline(always)]
fn capacity(&self) -> Option<usize> {
None
}
#[inline(always)]
fn is_full(&self) -> bool {
true
}
#[inline(always)]
fn is_empty(&self) -> bool {
true
}
}
impl FlavorImpl for Null {
#[inline(always)]
fn try_send(&self, _item: &MaybeUninit<()>) -> bool {
true
}
#[inline(always)]
fn try_send_oneshot(&self, _item: *const ()) -> Option<bool> {
Some(true)
}
#[inline(always)]
fn try_recv(&self) -> Option<Self::Item> {
None
}
#[inline(always)]
fn try_recv_final(&self) -> Option<Self::Item> {
None
}
#[inline]
fn backoff_limit(&self) -> u16 {
0
}
}
impl FlavorNew for Null {
#[inline]
fn new() -> Self {
Self()
}
}
impl FlavorSelect for Null {
#[inline(always)]
fn try_select(&self, _final_check: bool) -> Option<Token> {
None
}
#[inline(always)]
fn read_with_token(&self, _token: Token) {
unreachable!();
}
}
pub struct CloseHandle<F: Flavor>(Arc<ChannelShared<F>>);
impl<F: Flavor> Clone for CloseHandle<F> {
#[inline(always)]
fn clone(&self) -> Self {
self.0.add_tx();
Self(self.0.clone())
}
}
impl<F: Flavor> Drop for CloseHandle<F> {
#[inline(always)]
fn drop(&mut self) {
self.0.close_tx();
}
}
impl<F: Flavor> SenderType for CloseHandle<F>
where
F: Flavor<Item = ()>,
{
type Flavor = F;
#[inline(always)]
fn new(shared: Arc<ChannelShared<Self::Flavor>>) -> Self {
CloseHandle(shared)
}
}