@@ -48,10 +48,7 @@ use core::pin::Pin;
4848/// importance: you can use it to send an entire stream to a sink, which is
4949/// the simplest way to ultimately consume a stream.
5050#[ must_use = "sinks do nothing unless polled" ]
51- pub trait Sink {
52- /// The type of value that the sink accepts.
53- type SinkItem ;
54-
51+ pub trait Sink < Item > {
5552 /// The type of value produced by the sink when an error occurs.
5653 type SinkError ;
5754
@@ -88,7 +85,7 @@ pub trait Sink {
8885 ///
8986 /// In most cases, if the sink encounters an error, the sink will
9087 /// permanently be unable to receive items.
91- fn start_send ( self : Pin < & mut Self > , item : Self :: SinkItem )
88+ fn start_send ( self : Pin < & mut Self > , item : Item )
9289 -> Result < ( ) , Self :: SinkError > ;
9390
9491 /// Flush any remaining output from this sink.
@@ -119,15 +116,14 @@ pub trait Sink {
119116 fn poll_close ( self : Pin < & mut Self > , waker : & Waker ) -> Poll < Result < ( ) , Self :: SinkError > > ;
120117}
121118
122- impl < ' a , S : ?Sized + Sink + Unpin > Sink for & ' a mut S {
123- type SinkItem = S :: SinkItem ;
119+ impl < ' a , S : ?Sized + Sink < Item > + Unpin , Item > Sink < Item > for & ' a mut S {
124120 type SinkError = S :: SinkError ;
125121
126122 fn poll_ready ( mut self : Pin < & mut Self > , waker : & Waker ) -> Poll < Result < ( ) , Self :: SinkError > > {
127123 Pin :: new ( & mut * * self ) . poll_ready ( waker)
128124 }
129125
130- fn start_send ( mut self : Pin < & mut Self > , item : Self :: SinkItem ) -> Result < ( ) , Self :: SinkError > {
126+ fn start_send ( mut self : Pin < & mut Self > , item : Item ) -> Result < ( ) , Self :: SinkError > {
131127 Pin :: new ( & mut * * self ) . start_send ( item)
132128 }
133129
@@ -140,15 +136,14 @@ impl<'a, S: ?Sized + Sink + Unpin> Sink for &'a mut S {
140136 }
141137}
142138
143- impl < ' a , S : ?Sized + Sink > Sink for Pin < & ' a mut S > {
144- type SinkItem = S :: SinkItem ;
139+ impl < ' a , S : ?Sized + Sink < Item > , Item > Sink < Item > for Pin < & ' a mut S > {
145140 type SinkError = S :: SinkError ;
146141
147142 fn poll_ready ( mut self : Pin < & mut Self > , waker : & Waker ) -> Poll < Result < ( ) , Self :: SinkError > > {
148143 S :: poll_ready ( ( * self ) . as_mut ( ) , waker)
149144 }
150145
151- fn start_send ( mut self : Pin < & mut Self > , item : Self :: SinkItem ) -> Result < ( ) , Self :: SinkError > {
146+ fn start_send ( mut self : Pin < & mut Self > , item : Item ) -> Result < ( ) , Self :: SinkError > {
152147 S :: start_send ( ( * self ) . as_mut ( ) , item)
153148 }
154149
@@ -173,15 +168,14 @@ mod if_alloc {
173168 #[ derive( Copy , Clone , Debug ) ]
174169 pub enum VecSinkError { }
175170
176- impl < T > Sink for :: alloc:: vec:: Vec < T > {
177- type SinkItem = T ;
171+ impl < T > Sink < T > for :: alloc:: vec:: Vec < T > {
178172 type SinkError = VecSinkError ;
179173
180174 fn poll_ready ( self : Pin < & mut Self > , _: & Waker ) -> Poll < Result < ( ) , Self :: SinkError > > {
181175 Poll :: Ready ( Ok ( ( ) ) )
182176 }
183177
184- fn start_send ( self : Pin < & mut Self > , item : Self :: SinkItem ) -> Result < ( ) , Self :: SinkError > {
178+ fn start_send ( self : Pin < & mut Self > , item : T ) -> Result < ( ) , Self :: SinkError > {
185179 // TODO: impl<T> Unpin for Vec<T> {}
186180 unsafe { Pin :: get_unchecked_mut ( self ) } . push ( item) ;
187181 Ok ( ( ) )
@@ -196,15 +190,14 @@ mod if_alloc {
196190 }
197191 }
198192
199- impl < T > Sink for :: alloc:: collections:: VecDeque < T > {
200- type SinkItem = T ;
193+ impl < T > Sink < T > for :: alloc:: collections:: VecDeque < T > {
201194 type SinkError = VecSinkError ;
202195
203196 fn poll_ready ( self : Pin < & mut Self > , _: & Waker ) -> Poll < Result < ( ) , Self :: SinkError > > {
204197 Poll :: Ready ( Ok ( ( ) ) )
205198 }
206199
207- fn start_send ( self : Pin < & mut Self > , item : Self :: SinkItem ) -> Result < ( ) , Self :: SinkError > {
200+ fn start_send ( self : Pin < & mut Self > , item : T ) -> Result < ( ) , Self :: SinkError > {
208201 // TODO: impl<T> Unpin for Vec<T> {}
209202 unsafe { Pin :: get_unchecked_mut ( self ) } . push_back ( item) ;
210203 Ok ( ( ) )
@@ -219,15 +212,14 @@ mod if_alloc {
219212 }
220213 }
221214
222- impl < S : ?Sized + Sink + Unpin > Sink for :: alloc:: boxed:: Box < S > {
223- type SinkItem = S :: SinkItem ;
215+ impl < S : ?Sized + Sink < Item > + Unpin , Item > Sink < Item > for :: alloc:: boxed:: Box < S > {
224216 type SinkError = S :: SinkError ;
225217
226218 fn poll_ready ( mut self : Pin < & mut Self > , waker : & Waker ) -> Poll < Result < ( ) , Self :: SinkError > > {
227219 Pin :: new ( & mut * * self ) . poll_ready ( waker)
228220 }
229221
230- fn start_send ( mut self : Pin < & mut Self > , item : Self :: SinkItem ) -> Result < ( ) , Self :: SinkError > {
222+ fn start_send ( mut self : Pin < & mut Self > , item : Item ) -> Result < ( ) , Self :: SinkError > {
231223 Pin :: new ( & mut * * self ) . start_send ( item)
232224 }
233225
@@ -247,13 +239,11 @@ pub use self::if_alloc::*;
247239#[ cfg( feature = "either" ) ]
248240use either:: Either ;
249241#[ cfg( feature = "either" ) ]
250- impl < A , B > Sink for Either < A , B >
251- where A : Sink ,
252- B : Sink < SinkItem =<A as Sink >:: SinkItem ,
253- SinkError =<A as Sink >:: SinkError >
242+ impl < A , B , Item > Sink < Item > for Either < A , B >
243+ where A : Sink < Item > ,
244+ B : Sink < Item , SinkError =A :: SinkError > ,
254245{
255- type SinkItem = <A as Sink >:: SinkItem ;
256- type SinkError = <A as Sink >:: SinkError ;
246+ type SinkError = A :: SinkError ;
257247
258248 fn poll_ready ( self : Pin < & mut Self > , waker : & Waker ) -> Poll < Result < ( ) , Self :: SinkError > > {
259249 unsafe {
@@ -264,7 +254,7 @@ impl<A, B> Sink for Either<A, B>
264254 }
265255 }
266256
267- fn start_send ( self : Pin < & mut Self > , item : Self :: SinkItem ) -> Result < ( ) , Self :: SinkError > {
257+ fn start_send ( self : Pin < & mut Self > , item : Item ) -> Result < ( ) , Self :: SinkError > {
268258 unsafe {
269259 match Pin :: get_unchecked_mut ( self ) {
270260 Either :: Left ( x) => Pin :: new_unchecked ( x) . start_send ( item) ,
0 commit comments