mod acker;
mod app_id;
mod message;
mod req_id;
mod state;
pub use acker::Acker;
pub use app_id::AppId;
pub use message::Msg;
pub use req_id::ReqId;
pub use state::State;
use std::{convert::Infallible, error::Error};
use async_trait::async_trait;
use lapin::Channel;
use crate::Request;
#[async_trait]
pub trait Extract<S>: Sized {
type Error: Error;
async fn extract(req: &mut Request<S>) -> Result<Self, Self::Error>;
}
#[async_trait]
impl<S> Extract<S> for Channel
where
S: Send + Sync,
{
type Error = Infallible;
async fn extract(req: &mut Request<S>) -> Result<Self, Self::Error> {
Ok(req.channel().clone())
}
}
#[async_trait]
impl<S, T> Extract<S> for Option<T>
where
T: Extract<S>,
S: Send + Sync,
{
type Error = Infallible;
async fn extract(req: &mut Request<S>) -> Result<Self, Self::Error> {
Ok(Extract::extract(req).await.ok())
}
}
#[async_trait]
impl<S, T> Extract<S> for Result<T, <T as Extract<S>>::Error>
where
T: Extract<S>,
S: Send + Sync,
{
type Error = Infallible;
async fn extract(req: &mut Request<S>) -> Result<Self, Self::Error> {
Ok(Extract::extract(req).await)
}
}