From c4ab7290c519ba7c4847a8ed8c797a3826c1c1a8 Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Fri, 1 May 2020 14:27:53 +0200 Subject: [PATCH] remove static lifetimes from easylapin Unlike amqp::Consumer lapin channels don't need to have a 'static lifetime, the workers just need to live at least as long as the channel. --- ofborg/src/easyamqp.rs | 4 ++-- ofborg/src/easylapin.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ofborg/src/easyamqp.rs b/ofborg/src/easyamqp.rs index 3104e24..a253fa3 100644 --- a/ofborg/src/easyamqp.rs +++ b/ofborg/src/easyamqp.rs @@ -303,7 +303,7 @@ pub trait ChannelExt { fn bind_queue(&mut self, config: BindQueueConfig) -> Result<(), Self::Error>; } -pub trait ConsumerExt { +pub trait ConsumerExt<'a, C> { type Error; type Handle; fn consume(self, callback: C, config: ConsumeConfig) -> Result; @@ -351,7 +351,7 @@ impl ChannelExt for amqp::Channel { } } -impl ConsumerExt for amqp::Channel { +impl ConsumerExt<'_, C> for amqp::Channel { type Error = amqp::AMQPError; type Handle = Self; diff --git a/ofborg/src/easylapin.rs b/ofborg/src/easylapin.rs index c5c8eb6..1aeee73 100644 --- a/ofborg/src/easylapin.rs +++ b/ofborg/src/easylapin.rs @@ -80,9 +80,9 @@ impl ChannelExt for CloseOnDrop { } } -impl ConsumerExt for CloseOnDrop { +impl<'a, W: SimpleWorker + 'a> ConsumerExt<'a, W> for CloseOnDrop { type Error = lapin::Error; - type Handle = Pin + 'static>>; + type Handle = Pin + 'a>>; fn consume(self, mut worker: W, config: ConsumeConfig) -> Result { task::block_on(self.basic_qos(1, BasicQosOptions::default()))?; @@ -130,9 +130,9 @@ impl<'a> NotificationReceiver for ChannelNotificationReceiver<'a> { // but one could probably be implemented in terms of the other instead. pub struct NotifyChannel(pub CloseOnDrop); -impl ConsumerExt for NotifyChannel { +impl<'a, W: SimpleNotifyWorker + 'a> ConsumerExt<'a, W> for NotifyChannel { type Error = lapin::Error; - type Handle = Pin + 'static>>; + type Handle = Pin + 'a>>; fn consume(self, worker: W, config: ConsumeConfig) -> Result { task::block_on(self.0.basic_qos(1, BasicQosOptions::default()))?;