@@ -88,11 +88,13 @@ use std::future::Future;
88
88
use std:: net:: SocketAddr ;
89
89
#[ cfg( feature = "websocket" ) ]
90
90
use std:: pin:: Pin ;
91
+ #[ cfg( feature = "websocket" ) ]
91
92
use std:: task:: Context ;
92
93
#[ cfg( feature = "websocket" ) ]
93
94
use std:: task:: { self , Poll } ;
94
95
95
96
use bytes:: Bytes ;
97
+ #[ cfg( feature = "websocket" ) ]
96
98
use futures:: channel:: mpsc;
97
99
#[ cfg( feature = "websocket" ) ]
98
100
use futures:: StreamExt ;
@@ -107,11 +109,14 @@ use serde_json;
107
109
use tokio:: sync:: oneshot;
108
110
109
111
use crate :: filter:: Filter ;
112
+ #[ cfg( feature = "websocket" ) ]
110
113
use crate :: filters:: ws:: Message ;
111
114
use crate :: reject:: IsReject ;
112
115
use crate :: reply:: Reply ;
113
116
use crate :: route:: { self , Route } ;
114
- use crate :: { Request , Sink } ;
117
+ use crate :: Request ;
118
+ #[ cfg( feature = "websocket" ) ]
119
+ use crate :: { Sink , Stream } ;
115
120
116
121
use self :: inner:: OneOrTuple ;
117
122
@@ -646,6 +651,21 @@ impl Sink<crate::ws::Message> for WsClient {
646
651
}
647
652
}
648
653
654
+ #[ cfg( feature = "websocket" ) ]
655
+ impl Stream for WsClient {
656
+ type Item = Result < crate :: ws:: Message , WsError > ;
657
+
658
+ fn poll_next ( self : Pin < & mut Self > , context : & mut Context < ' _ > ) -> Poll < Option < Self :: Item > > {
659
+ let this = Pin :: into_inner ( self ) ;
660
+ let rx = Pin :: new ( & mut this. rx ) ;
661
+ match rx. poll_next ( context) {
662
+ Poll :: Ready ( Some ( result) ) => Poll :: Ready ( Some ( result. map_err ( WsError :: new) ) ) ,
663
+ Poll :: Ready ( None ) => Poll :: Ready ( None ) ,
664
+ Poll :: Pending => Poll :: Pending ,
665
+ }
666
+ }
667
+ }
668
+
649
669
// ===== impl WsError =====
650
670
651
671
#[ cfg( feature = "websocket" ) ]
0 commit comments