use std::{any::type_name, borrow::Cow, marker::PhantomData};
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct HandlerMetadata {
pub topic: Cow<'static, str>,
pub routing_key: Option<Cow<'static, str>>,
pub input_type: &'static str,
pub output_type: Option<&'static str>,
pub description: Option<Cow<'static, str>>,
}
impl HandlerMetadata {
#[must_use]
pub fn raw(topic: impl Into<Cow<'static, str>>) -> Self {
Self {
topic: topic.into(),
routing_key: None,
input_type: "bytes",
output_type: None,
description: None,
}
}
#[must_use]
pub fn typed<T>(topic: impl Into<Cow<'static, str>>) -> Self {
let _ = PhantomData::<T>;
Self {
topic: topic.into(),
routing_key: None,
input_type: type_name::<T>(),
output_type: None,
description: None,
}
}
#[must_use]
pub fn with_description(mut self, description: impl Into<Cow<'static, str>>) -> Self {
self.description = Some(description.into());
self
}
#[must_use]
pub fn with_routing_key(mut self, key: impl Into<Cow<'static, str>>) -> Self {
self.routing_key = Some(key.into());
self
}
#[must_use]
pub fn with_output_type(mut self, name: &'static str) -> Self {
self.output_type = Some(name);
self
}
}