@@ -88,6 +88,7 @@ use std::future::Future;
88
88
use std:: net:: SocketAddr ;
89
89
#[ cfg( feature = "websocket" ) ]
90
90
use std:: pin:: Pin ;
91
+ use std:: task:: Context ;
91
92
#[ cfg( feature = "websocket" ) ]
92
93
use std:: task:: { self , Poll } ;
93
94
@@ -106,10 +107,11 @@ use serde_json;
106
107
use tokio:: sync:: oneshot;
107
108
108
109
use crate :: filter:: Filter ;
110
+ use crate :: filters:: ws:: Message ;
109
111
use crate :: reject:: IsReject ;
110
112
use crate :: reply:: Reply ;
111
113
use crate :: route:: { self , Route } ;
112
- use crate :: Request ;
114
+ use crate :: { Request , Sink } ;
113
115
114
116
use self :: inner:: OneOrTuple ;
115
117
@@ -600,6 +602,11 @@ impl WsClient {
600
602
Ok ( ( ) )
601
603
} )
602
604
}
605
+
606
+ fn pinned_tx ( self : Pin < & mut Self > ) -> Pin < & mut mpsc:: UnboundedSender < crate :: ws:: Message > > {
607
+ let this = Pin :: into_inner ( self ) ;
608
+ Pin :: new ( & mut this. tx )
609
+ }
603
610
}
604
611
605
612
#[ cfg( feature = "websocket" ) ]
@@ -609,6 +616,36 @@ impl fmt::Debug for WsClient {
609
616
}
610
617
}
611
618
619
+ #[ cfg( feature = "websocket" ) ]
620
+ impl Sink < crate :: ws:: Message > for WsClient {
621
+ type Error = ( ) ;
622
+
623
+ fn poll_ready (
624
+ self : Pin < & mut Self > ,
625
+ context : & mut Context < ' _ > ,
626
+ ) -> Poll < Result < ( ) , Self :: Error > > {
627
+ self . pinned_tx ( ) . poll_ready ( context) . map_err ( |_| ( ) )
628
+ }
629
+
630
+ fn start_send ( self : Pin < & mut Self > , message : Message ) -> Result < ( ) , Self :: Error > {
631
+ self . pinned_tx ( ) . start_send ( message) . map_err ( |_| ( ) )
632
+ }
633
+
634
+ fn poll_flush (
635
+ self : Pin < & mut Self > ,
636
+ context : & mut Context < ' _ > ,
637
+ ) -> Poll < Result < ( ) , Self :: Error > > {
638
+ self . pinned_tx ( ) . poll_flush ( context) . map_err ( |_| ( ) )
639
+ }
640
+
641
+ fn poll_close (
642
+ self : Pin < & mut Self > ,
643
+ context : & mut Context < ' _ > ,
644
+ ) -> Poll < Result < ( ) , Self :: Error > > {
645
+ self . pinned_tx ( ) . poll_close ( context) . map_err ( |_| ( ) )
646
+ }
647
+ }
648
+
612
649
// ===== impl WsError =====
613
650
614
651
#[ cfg( feature = "websocket" ) ]
0 commit comments