@@ -5,24 +5,25 @@ use async_nats::HeaderMap;
55use async_nats:: jetstream:: consumer:: pull;
66use async_nats:: jetstream:: publish:: PublishAck ;
77use async_nats:: jetstream:: stream;
8+ use async_nats:: subject:: ToSubject ;
89use bytes:: Bytes ;
910use futures:: Stream ;
1011
1112pub trait JetStreamContext : Send + Sync + Clone + ' static {
1213 type Error : Error + Send + Sync ;
1314
14- fn get_or_create_stream (
15+ fn get_or_create_stream < S : Into < stream :: Config > + Send > (
1516 & self ,
16- config : stream :: Config ,
17+ config : S ,
1718 ) -> impl Future < Output = Result < ( ) , Self :: Error > > + Send ;
1819}
1920
2021pub trait JetStreamPublisher : Send + Sync + Clone + ' static {
2122 type PublishError : Error + Send + Sync ;
2223
23- fn js_publish_with_headers (
24+ fn js_publish_with_headers < S : ToSubject + Send > (
2425 & self ,
25- subject : String ,
26+ subject : S ,
2627 headers : HeaderMap ,
2728 payload : Bytes ,
2829 ) -> impl Future < Output = Result < PublishAck , Self :: PublishError > > + Send ;
@@ -64,9 +65,9 @@ impl Error for NoJetStream {}
6465impl JetStreamPublisher for ( ) {
6566 type PublishError = NoJetStream ;
6667
67- async fn js_publish_with_headers (
68+ async fn js_publish_with_headers < S : ToSubject + Send > (
6869 & self ,
69- _subject : String ,
70+ _subject : S ,
7071 _headers : HeaderMap ,
7172 _payload : Bytes ,
7273 ) -> Result < PublishAck , NoJetStream > {
@@ -193,7 +194,7 @@ mod tests {
193194
194195 #[ tokio:: test]
195196 async fn unit_publisher_returns_err ( ) {
196- let result = ( ) . js_publish_with_headers ( "s" . into ( ) , HeaderMap :: new ( ) , Bytes :: new ( ) ) . await ;
197+ let result = ( ) . js_publish_with_headers ( "s" , HeaderMap :: new ( ) , Bytes :: new ( ) ) . await ;
197198 assert ! ( result. is_err( ) ) ;
198199 }
199200
0 commit comments