@@ -697,7 +697,7 @@ impl Context {
697697 T : Sized + Serialize ,
698698 V : DeserializeOwned ,
699699 {
700- Request :: new ( self . clone ( ) , subject, payload)
700+ Request :: new ( self , subject, payload)
701701 }
702702
703703 /// Creates a new object store bucket.
@@ -1117,16 +1117,16 @@ impl<'a> IntoFuture for Publish<'a> {
11171117}
11181118
11191119#[ derive( Debug ) ]
1120- pub struct Request < T : Sized + Serialize , V : DeserializeOwned > {
1121- context : Context ,
1120+ pub struct Request < ' a , T : Sized + Serialize , V : DeserializeOwned > {
1121+ context : & ' a Context ,
11221122 subject : String ,
11231123 payload : T ,
11241124 timeout : Option < Duration > ,
11251125 response_type : PhantomData < V > ,
11261126}
11271127
1128- impl < T : Sized + Serialize , V : DeserializeOwned > Request < T , V > {
1129- pub fn new ( context : Context , subject : String , payload : T ) -> Self {
1128+ impl < ' a , T : Sized + Serialize , V : DeserializeOwned > Request < ' a , T , V > {
1129+ pub fn new ( context : & ' a Context , subject : String , payload : T ) -> Self {
11301130 Self {
11311131 context,
11321132 subject,
@@ -1142,24 +1142,28 @@ impl<T: Sized + Serialize, V: DeserializeOwned> Request<T, V> {
11421142 }
11431143}
11441144
1145- impl < T : Sized + Serialize , V : DeserializeOwned > IntoFuture for Request < T , V > {
1145+ impl < ' a , T : Sized + Serialize , V : DeserializeOwned > IntoFuture for Request < ' a , T , V > {
11461146 type Output = Result < Response < V > , Error > ;
11471147
11481148 type IntoFuture = Pin < Box < dyn Future < Output = Result < Response < V > , Error > > + Send > > ;
11491149
11501150 fn into_future ( self ) -> Self :: IntoFuture {
11511151 let payload_result = serde_json:: to_vec ( & self . payload ) . map ( Bytes :: from) ;
11521152
1153- let prefix = self . context . prefix ;
1154- let client = self . context . client ;
11551153 let subject = self . subject ;
11561154 let timeout = self . timeout ;
11571155
1156+ let context = & self . context ;
1157+
1158+ // TODO: Get rid of this cloning below
1159+ let prefix = context. prefix . clone ( ) ;
1160+ let client = context. client . clone ( ) ;
1161+
11581162 Box :: pin ( std:: future:: IntoFuture :: into_future ( async move {
11591163 let payload = payload_result?;
11601164 debug ! ( "JetStream request sent: {:?}" , payload) ;
11611165
1162- let request = client. request ( format ! ( "{}.{}" , prefix, subject) , payload) ;
1166+ let request = client. request ( format ! ( "{}.{}" , prefix, subject) , payload. clone ( ) ) ;
11631167 let request = request. timeout ( timeout) ;
11641168 let message = request. await ?;
11651169
0 commit comments