11use crate :: shared:: UnsafeShared ;
2+ use crate :: sync:: error:: { SendError , TrySendError } ;
23use futures:: Stream ;
34use std:: cell:: UnsafeCell ;
45use std:: collections:: VecDeque ;
56use std:: rc:: Rc ;
67use std:: task:: { Context , Poll , Waker } ;
7- use std:: { fmt, io} ;
88use std:: { future:: poll_fn, pin:: Pin } ;
99
1010struct State < T > {
@@ -25,17 +25,6 @@ fn take_and_wake(waker: &mut Option<Waker>) {
2525 waker. take ( ) . inspect ( Waker :: wake_by_ref) ;
2626}
2727
28- #[ derive( PartialEq , Eq ) ]
29- pub enum TrySendError < T > {
30- Full ( T ) ,
31- Closed ( T ) ,
32- }
33-
34- #[ derive( PartialEq , Eq ) ]
35- pub enum SendError < T > {
36- Closed ( T ) ,
37- }
38-
3928/// Bounded SPSC channel
4029pub fn channel < T > ( limit : usize ) -> ( Sender < T > , Receiver < T > ) {
4130 let shared = Rc :: new ( UnsafeCell :: new ( State {
@@ -170,63 +159,6 @@ impl<T> Drop for Receiver<T> {
170159 }
171160}
172161
173- impl < T > fmt:: Debug for TrySendError < T > {
174- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
175- match self {
176- TrySendError :: Full ( _) => f. write_str ( "TrySendError::Full(..)" ) ,
177- TrySendError :: Closed ( _) => f. write_str ( "TrySendError::Closed(..)" ) ,
178- }
179- }
180- }
181-
182- impl < T > fmt:: Display for TrySendError < T > {
183- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
184- match self {
185- TrySendError :: Full ( _) => f. write_str ( "channel is full" ) ,
186- TrySendError :: Closed ( _) => f. write_str ( "channel is closed" ) ,
187- }
188- }
189- }
190-
191- impl < T > std:: error:: Error for TrySendError < T > { }
192-
193- impl < T > From < TrySendError < T > > for io:: Error {
194- fn from ( err : TrySendError < T > ) -> Self {
195- let source = format ! ( "{err}" ) ;
196- match err {
197- TrySendError :: Full ( _) => io:: Error :: new ( io:: ErrorKind :: StorageFull , source) ,
198- TrySendError :: Closed ( _) => io:: Error :: new ( io:: ErrorKind :: BrokenPipe , source) ,
199- }
200- }
201- }
202-
203- impl < T > fmt:: Debug for SendError < T > {
204- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
205- match self {
206- SendError :: Closed ( _) => f. write_str ( "SendError::Closed(..)" ) ,
207- }
208- }
209- }
210-
211- impl < T > fmt:: Display for SendError < T > {
212- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
213- match self {
214- SendError :: Closed ( _) => f. write_str ( "channel is closed" ) ,
215- }
216- }
217- }
218-
219- impl < T > std:: error:: Error for SendError < T > { }
220-
221- impl < T > From < SendError < T > > for io:: Error {
222- fn from ( err : SendError < T > ) -> Self {
223- let source = format ! ( "{err}" ) ;
224- match err {
225- SendError :: Closed ( _) => io:: Error :: new ( io:: ErrorKind :: BrokenPipe , source) ,
226- }
227- }
228- }
229-
230162#[ cfg( test) ]
231163mod tests {
232164 use super :: * ;
0 commit comments