make amqp error type generic

This commit is contained in:
Daiderd Jordan 2020-04-27 22:12:31 +02:00
parent a87cf357d0
commit a34a4accaf
No known key found for this signature in database
GPG key ID: D02435D05B810C96

View file

@ -297,28 +297,32 @@ pub fn session_from_config(config: &RabbitMQConfig) -> Result<amqp::Session, amq
} }
pub trait TypedWrappers { pub trait TypedWrappers {
fn consume<T>(&mut self, callback: T, config: ConsumeConfig) -> Result<String, amqp::AMQPError> type Error;
fn consume<T>(&mut self, callback: T, config: ConsumeConfig) -> Result<String, Self::Error>
where where
T: amqp::Consumer + 'static; T: amqp::Consumer + 'static;
fn declare_exchange( fn declare_exchange(
&mut self, &mut self,
config: ExchangeConfig, config: ExchangeConfig,
) -> Result<amqp::protocol::exchange::DeclareOk, amqp::AMQPError>; ) -> Result<amqp::protocol::exchange::DeclareOk, Self::Error>;
fn declare_queue( fn declare_queue(
&mut self, &mut self,
config: QueueConfig, config: QueueConfig,
) -> Result<amqp::protocol::queue::DeclareOk, amqp::AMQPError>; ) -> Result<amqp::protocol::queue::DeclareOk, Self::Error>;
fn bind_queue( fn bind_queue(
&mut self, &mut self,
config: BindQueueConfig, config: BindQueueConfig,
) -> Result<amqp::protocol::queue::BindOk, amqp::AMQPError>; ) -> Result<amqp::protocol::queue::BindOk, Self::Error>;
} }
impl TypedWrappers for amqp::Channel { impl TypedWrappers for amqp::Channel {
fn consume<T>(&mut self, callback: T, config: ConsumeConfig) -> Result<String, amqp::AMQPError> type Error = amqp::AMQPError;
fn consume<T>(&mut self, callback: T, config: ConsumeConfig) -> Result<String, Self::Error>
where where
T: amqp::Consumer + 'static, T: amqp::Consumer + 'static,
{ {
@ -337,7 +341,7 @@ impl TypedWrappers for amqp::Channel {
fn declare_exchange( fn declare_exchange(
&mut self, &mut self,
config: ExchangeConfig, config: ExchangeConfig,
) -> Result<amqp::protocol::exchange::DeclareOk, amqp::AMQPError> { ) -> Result<amqp::protocol::exchange::DeclareOk, Self::Error> {
self.exchange_declare( self.exchange_declare(
config.exchange, config.exchange,
config.exchange_type.into(), config.exchange_type.into(),
@ -353,7 +357,7 @@ impl TypedWrappers for amqp::Channel {
fn declare_queue( fn declare_queue(
&mut self, &mut self,
config: QueueConfig, config: QueueConfig,
) -> Result<amqp::protocol::queue::DeclareOk, amqp::AMQPError> { ) -> Result<amqp::protocol::queue::DeclareOk, Self::Error> {
self.queue_declare( self.queue_declare(
config.queue, config.queue,
config.passive, config.passive,
@ -368,7 +372,7 @@ impl TypedWrappers for amqp::Channel {
fn bind_queue( fn bind_queue(
&mut self, &mut self,
config: BindQueueConfig, config: BindQueueConfig,
) -> Result<amqp::protocol::queue::BindOk, amqp::AMQPError> { ) -> Result<amqp::protocol::queue::BindOk, Self::Error> {
self.queue_bind( self.queue_bind(
config.queue, config.queue,
config.exchange, config.exchange,