diff --git a/src/lib.rs b/src/lib.rs index 945efd6..20507e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,20 +106,17 @@ #![cfg_attr(docsrs, feature(doc_cfg))] use std::{collections::BTreeMap, time::SystemTime}; - +pub use topic::Topic; use uuid::Uuid; #[cfg(feature = "publish")] #[cfg_attr(docsrs, doc(cfg(feature = "publish")))] pub mod publish; - #[cfg(test)] mod tests; +mod topic; pub mod validators; -/// A message queue topic name to which messages can be published -pub type Topic = &'static str; - /// All errors that may be returned when operating top level APIs. #[derive(Debug, thiserror::Error)] #[non_exhaustive] diff --git a/src/publish/mod.rs b/src/publish/mod.rs index f943731..8b68124 100644 --- a/src/publish/mod.rs +++ b/src/publish/mod.rs @@ -185,7 +185,7 @@ where None => None, Some(stream_item) => Some(( stream_item, - this.topic, + *this.topic, this.messages .next() .expect("should be as many messages as publishes"), diff --git a/src/publish/publishers/null.rs b/src/publish/publishers/null.rs index 6721c44..00fcf53 100644 --- a/src/publish/publishers/null.rs +++ b/src/publish/publishers/null.rs @@ -20,7 +20,7 @@ impl Publisher for NullPublisher { type MessageError = std::convert::Infallible; type PublishStream = NullPublishStream; - fn publish<'a, I>(&self, _: &'static str, messages: I) -> Self::PublishStream + fn publish<'a, I>(&self, _: crate::Topic, messages: I) -> Self::PublishStream where I: Iterator + ExactSizeIterator, { diff --git a/src/topic.rs b/src/topic.rs new file mode 100644 index 0000000..e05952a --- /dev/null +++ b/src/topic.rs @@ -0,0 +1,21 @@ +/// A message queue topic name to which messages can be published +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +pub struct Topic(pub &'static str); + +impl std::fmt::Display for Topic { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + std::fmt::Display::fmt(self.0, f) + } +} + +impl From<&'static str> for Topic { + fn from(s: &'static str) -> Topic { + Topic(s) + } +} + +impl From for &'static str { + fn from(s: Topic) -> &'static str { + s.0 + } +}