From 3fbf7c889e491f1821422ad6859a14f8fa0115d3 Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Wed, 1 Nov 2023 10:16:31 +0100 Subject: [PATCH] Rename AsSubject to ToSubject Signed-off-by: Tomasz Pietrek --- async-nats/src/client.rs | 42 ++++++++++++++--------------- async-nats/src/jetstream/context.rs | 14 +++++----- async-nats/src/subject.rs | 16 +++++------ 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/async-nats/src/client.rs b/async-nats/src/client.rs index 859d7fd6c..83b224d66 100644 --- a/async-nats/src/client.rs +++ b/async-nats/src/client.rs @@ -12,7 +12,7 @@ // limitations under the License. use crate::connection::State; -use crate::subject::AsSubject; +use crate::subject::ToSubject; use crate::ServerInfo; use super::{header::HeaderMap, status::StatusCode, Command, Message, Subscriber}; @@ -148,12 +148,12 @@ impl Client { /// # Ok(()) /// # } /// ``` - pub async fn publish( + pub async fn publish( &self, subject: S, payload: Bytes, ) -> Result<(), PublishError> { - let subject = subject.as_subject(); + let subject = subject.to_subject(); self.sender .send(Command::Publish { @@ -185,13 +185,13 @@ impl Client { /// # Ok(()) /// # } /// ``` - pub async fn publish_with_headers( + pub async fn publish_with_headers( &self, subject: S, headers: HeaderMap, payload: Bytes, ) -> Result<(), PublishError> { - let subject = subject.as_subject(); + let subject = subject.to_subject(); self.sender .send(Command::Publish { @@ -220,14 +220,14 @@ impl Client { /// # Ok(()) /// # } /// ``` - pub async fn publish_with_reply( + pub async fn publish_with_reply( &self, subject: S, reply: R, payload: Bytes, ) -> Result<(), PublishError> { - let subject = subject.as_subject(); - let reply = reply.as_subject(); + let subject = subject.to_subject(); + let reply = reply.to_subject(); self.sender .send(Command::Publish { @@ -258,15 +258,15 @@ impl Client { /// # Ok(()) /// # } /// ``` - pub async fn publish_with_reply_and_headers( + pub async fn publish_with_reply_and_headers( &self, subject: S, reply: R, headers: HeaderMap, payload: Bytes, ) -> Result<(), PublishError> { - let subject = subject.as_subject(); - let reply = reply.as_subject(); + let subject = subject.to_subject(); + let reply = reply.to_subject(); self.sender .send(Command::Publish { @@ -290,12 +290,12 @@ impl Client { /// # Ok(()) /// # } /// ``` - pub async fn request( + pub async fn request( &self, subject: S, payload: Bytes, ) -> Result { - let subject = subject.as_subject(); + let subject = subject.to_subject(); trace!( "request sent to subject: {} ({})", @@ -321,13 +321,13 @@ impl Client { /// # Ok(()) /// # } /// ``` - pub async fn request_with_headers( + pub async fn request_with_headers( &self, subject: S, headers: HeaderMap, payload: Bytes, ) -> Result { - let subject = subject.as_subject(); + let subject = subject.to_subject(); let request = Request::new().headers(headers).payload(payload); self.send_request(subject, request).await @@ -346,12 +346,12 @@ impl Client { /// # Ok(()) /// # } /// ``` - pub async fn send_request( + pub async fn send_request( &self, subject: S, request: Request, ) -> Result { - let subject = subject.as_subject(); + let subject = subject.to_subject(); if let Some(inbox) = request.inbox { let timeout = request.timeout.unwrap_or(self.request_timeout); @@ -463,8 +463,8 @@ impl Client { /// # Ok(()) /// # } /// ``` - pub async fn subscribe(&self, subject: S) -> Result { - let subject = subject.as_subject(); + pub async fn subscribe(&self, subject: S) -> Result { + let subject = subject.to_subject(); let sid = self.next_subscription_id.fetch_add(1, Ordering::Relaxed); let (sender, receiver) = mpsc::channel(self.subscription_capacity); @@ -496,12 +496,12 @@ impl Client { /// # Ok(()) /// # } /// ``` - pub async fn queue_subscribe( + pub async fn queue_subscribe( &self, subject: S, queue_group: String, ) -> Result { - let subject = subject.as_subject(); + let subject = subject.to_subject(); let sid = self.next_subscription_id.fetch_add(1, Ordering::Relaxed); let (sender, receiver) = mpsc::channel(self.subscription_capacity); diff --git a/async-nats/src/jetstream/context.rs b/async-nats/src/jetstream/context.rs index 5d5a92076..8c09821f0 100644 --- a/async-nats/src/jetstream/context.rs +++ b/async-nats/src/jetstream/context.rs @@ -18,7 +18,7 @@ use crate::header::{IntoHeaderName, IntoHeaderValue}; use crate::jetstream::account::Account; use crate::jetstream::publish::PublishAck; use crate::jetstream::response::Response; -use crate::subject::AsSubject; +use crate::subject::ToSubject; use crate::{header, Client, Command, HeaderMap, HeaderValue, Message, StatusCode}; use bytes::Bytes; use futures::future::BoxFuture; @@ -120,7 +120,7 @@ impl Context { /// # Ok(()) /// # } /// ``` - pub async fn publish( + pub async fn publish( &self, subject: S, payload: Bytes, @@ -150,7 +150,7 @@ impl Context { /// # Ok(()) /// # } /// ``` - pub async fn publish_with_headers( + pub async fn publish_with_headers( &self, subject: S, headers: crate::header::HeaderMap, @@ -182,12 +182,12 @@ impl Context { /// # Ok(()) /// # } /// ``` - pub async fn send_publish( + pub async fn send_publish( &self, subject: S, publish: Publish, ) -> Result { - let subject = subject.as_subject(); + let subject = subject.to_subject(); let (sender, receiver) = oneshot::channel(); let respond = self.client.new_inbox().into(); @@ -805,11 +805,11 @@ impl Context { /// ``` pub async fn request(&self, subject: S, payload: &T) -> Result where - S: AsSubject, + S: ToSubject, T: ?Sized + Serialize, V: DeserializeOwned, { - let subject = subject.as_subject(); + let subject = subject.to_subject(); let request = serde_json::to_vec(&payload) .map(Bytes::from) .map_err(|err| RequestError::with_source(RequestErrorKind::Other, err))?; diff --git a/async-nats/src/subject.rs b/async-nats/src/subject.rs index b97189b27..a65d10a3f 100644 --- a/async-nats/src/subject.rs +++ b/async-nats/src/subject.rs @@ -111,24 +111,24 @@ impl fmt::Display for Subject { } } -pub trait AsSubject { - fn as_subject(&self) -> Subject; +pub trait ToSubject { + fn to_subject(&self) -> Subject; } -impl AsSubject for Subject { - fn as_subject(&self) -> Subject { +impl ToSubject for Subject { + fn to_subject(&self) -> Subject { self.to_owned() } } -impl AsSubject for &'static str { - fn as_subject(&self) -> Subject { +impl ToSubject for &'static str { + fn to_subject(&self) -> Subject { Subject::from_static(self) } } -impl AsSubject for String { - fn as_subject(&self) -> Subject { +impl ToSubject for String { + fn to_subject(&self) -> Subject { Subject::from(self.as_str()) } }