@@ -88,6 +88,7 @@ use async_trait::async_trait;
88
88
use dashmap:: DashMap ;
89
89
use dashmap:: DashSet ;
90
90
use dashmap:: mapref:: entry:: Entry ;
91
+ use futures:: Sink ;
91
92
use serde:: Deserialize ;
92
93
use serde:: Serialize ;
93
94
use serde:: de:: DeserializeOwned ;
@@ -108,6 +109,7 @@ use crate::actor::Signal;
108
109
use crate :: actor:: remote:: USER_PORT_OFFSET ;
109
110
use crate :: attrs:: Attrs ;
110
111
use crate :: cap;
112
+ use crate :: cap:: CanSend ;
111
113
use crate :: channel;
112
114
use crate :: channel:: ChannelAddr ;
113
115
use crate :: channel:: ChannelError ;
@@ -970,6 +972,39 @@ impl MailboxSender for MailboxClient {
970
972
}
971
973
}
972
974
975
+ /// Wrapper to turn `PortRef` into a `Sink`.
976
+ pub struct PortSink < ' a , C : CanSend , M : RemoteMessage > {
977
+ caps : & ' a C ,
978
+ port : PortRef < M > ,
979
+ }
980
+
981
+ impl < ' a , C : CanSend , M : RemoteMessage > PortSink < ' a , C , M > {
982
+ /// Create new PortSink
983
+ pub fn new ( caps : & ' a C , port : PortRef < M > ) -> Self {
984
+ Self { caps, port }
985
+ }
986
+ }
987
+
988
+ impl < ' a , C : CanSend , M : RemoteMessage > Sink < M > for PortSink < ' a , C , M > {
989
+ type Error = MailboxSenderError ;
990
+
991
+ fn poll_ready ( self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , Self :: Error > > {
992
+ Poll :: Ready ( Ok ( ( ) ) )
993
+ }
994
+
995
+ fn start_send ( self : Pin < & mut Self > , item : M ) -> Result < ( ) , Self :: Error > {
996
+ self . port . send ( self . caps , item)
997
+ }
998
+
999
+ fn poll_flush ( self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , Self :: Error > > {
1000
+ Poll :: Ready ( Ok ( ( ) ) )
1001
+ }
1002
+
1003
+ fn poll_close ( self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , Self :: Error > > {
1004
+ Poll :: Ready ( Ok ( ( ) ) )
1005
+ }
1006
+ }
1007
+
973
1008
/// A mailbox coordinates message delivery to actors through typed
974
1009
/// [`Port`]s associated with the mailbox.
975
1010
#[ derive( Clone , Debug ) ]
0 commit comments