crossbeam_channel/flavors/
never.rs
1use std::marker::PhantomData;
6use std::time::Instant;
7
8use crate::context::Context;
9use crate::err::{RecvTimeoutError, TryRecvError};
10use crate::select::{Operation, SelectHandle, Token};
11use crate::utils;
12
13pub(crate) type NeverToken = ();
15
16pub(crate) struct Channel<T> {
18 _marker: PhantomData<T>,
19}
20
21impl<T> Channel<T> {
22 #[inline]
24 pub(crate) fn new() -> Self {
25 Channel {
26 _marker: PhantomData,
27 }
28 }
29
30 #[inline]
32 pub(crate) fn try_recv(&self) -> Result<T, TryRecvError> {
33 Err(TryRecvError::Empty)
34 }
35
36 #[inline]
38 pub(crate) fn recv(&self, deadline: Option<Instant>) -> Result<T, RecvTimeoutError> {
39 utils::sleep_until(deadline);
40 Err(RecvTimeoutError::Timeout)
41 }
42
43 #[inline]
45 pub(crate) unsafe fn read(&self, _token: &mut Token) -> Result<T, ()> {
46 Err(())
47 }
48
49 #[inline]
51 pub(crate) fn is_empty(&self) -> bool {
52 true
53 }
54
55 #[inline]
57 pub(crate) fn is_full(&self) -> bool {
58 true
59 }
60
61 #[inline]
63 pub(crate) fn len(&self) -> usize {
64 0
65 }
66
67 #[allow(clippy::unnecessary_wraps)] #[inline]
70 pub(crate) fn capacity(&self) -> Option<usize> {
71 Some(0)
72 }
73}
74
75impl<T> SelectHandle for Channel<T> {
76 #[inline]
77 fn try_select(&self, _token: &mut Token) -> bool {
78 false
79 }
80
81 #[inline]
82 fn deadline(&self) -> Option<Instant> {
83 None
84 }
85
86 #[inline]
87 fn register(&self, _oper: Operation, _cx: &Context) -> bool {
88 self.is_ready()
89 }
90
91 #[inline]
92 fn unregister(&self, _oper: Operation) {}
93
94 #[inline]
95 fn accept(&self, token: &mut Token, _cx: &Context) -> bool {
96 self.try_select(token)
97 }
98
99 #[inline]
100 fn is_ready(&self) -> bool {
101 false
102 }
103
104 #[inline]
105 fn watch(&self, _oper: Operation, _cx: &Context) -> bool {
106 self.is_ready()
107 }
108
109 #[inline]
110 fn unwatch(&self, _oper: Operation) {}
111}