macro_rules! identity_macro {
($input:tt) => {
$input
};
}
pub(crate) use identity_macro;
macro_rules! impl_queue {
(
/// The type to implement the `Queue` trait for.
$for_type:ty,
/// Expression used to transform `self` into an implementation-specific executor type.
$transform_self:tt
) => {
impl crate::private::Sealed for $for_type {}
#[async_trait::async_trait]
impl crate::queue::Queue for $for_type {
async fn create<'q, Q, QE>(self, queue_name: Q) -> Result<(), crate::errors::PgmqError>
where
Q: Send + TryInto<crate::types::QueueName<'q>, Error = QE>,
QE: ToString,
{
let queue_name = queue_name
.try_into()
.map_err(crate::types::queue_name::QueueNameError::other)?;
create($transform_self!(self), queue_name).await
}
async fn send<'q, T, H, Q, QE, D>(
self,
queue_name: Q,
message: T,
headers: H,
delay: D,
) -> Result<i64, crate::errors::PgmqError>
where
T: Send + serde::Serialize,
H: Send + serde::Serialize,
Q: Send + TryInto<crate::types::QueueName<'q>, Error = QE>,
QE: ToString,
D: Send + Into<crate::types::VisibilityTimeoutOffset>,
{
let queue_name = queue_name
.try_into()
.map_err(crate::types::queue_name::QueueNameError::other)?;
let delay: crate::types::VisibilityTimeoutOffset = delay.into();
let message = serde_json::to_value(message)?;
let headers = serde_json::to_value(headers)?;
send($transform_self!(self), queue_name, message, headers, delay).await
}
async fn read<'q, T, Q, QE, VT>(
self,
queue_name: Q,
visibility_timeout: VT,
quantity: i32,
) -> Result<Vec<crate::types::Message<T>>, crate::errors::PgmqError>
where
T: 'static + Send + for<'de> serde::Deserialize<'de>,
Q: Send + TryInto<crate::types::QueueName<'q>, Error = QE>,
QE: ToString,
VT: Send + Into<crate::types::VisibilityTimeoutOffset>,
{
let queue_name = queue_name
.try_into()
.map_err(crate::types::queue_name::QueueNameError::other)?;
let visibility_timeout: crate::types::VisibilityTimeoutOffset =
visibility_timeout.into();
read(
$transform_self!(self),
queue_name,
visibility_timeout,
quantity,
)
.await
}
}
};
}
pub(crate) use impl_queue;