From 267ff63016fc826438ffd9f202cad5ac0f549351 Mon Sep 17 00:00:00 2001 From: Gregor Reitzenstein Date: Thu, 17 Sep 2020 11:57:45 +0200 Subject: [PATCH] Improves lifetimes to be more ergonomic --- src/registries/sensors.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/registries/sensors.rs b/src/registries/sensors.rs index 042a00c..b926989 100644 --- a/src/registries/sensors.rs +++ b/src/registries/sensors.rs @@ -20,8 +20,8 @@ impl Sensors { } } -pub type SensBox<'a> = Box>; -type Inner = HashMap>; +pub type SensBox = Box; +type Inner = HashMap; // Implementing Sensors. @@ -35,13 +35,14 @@ type Inner = HashMap>; /// A sensor is anything that can forward an intent of an user to do something to bffh. /// This may be a card reader connected to a machine, a website allowing users to select a machine /// they want to use or something like QRHello -pub trait Sensor<'a>: Stream> { +pub trait Sensor: Stream> { /// Setup the Sensor. /// /// After this async function completes the Stream implementation should be able to generate /// futures when polled. /// Implementations can rely on this function being polled to completeion before the stream /// is polled. + // TODO Is this sensible vs just having module-specific setup fns? async fn setup(&mut self); /// Shutdown the sensor gracefully @@ -51,11 +52,9 @@ pub trait Sensor<'a>: Stream> { async fn shutdown(&mut self); } -struct Dummy<'a> { - phantom: &'a std::marker::PhantomData<()>, -} +struct Dummy; #[async_trait] -impl<'a> Sensor<'a> for Dummy<'a> { +impl Sensor for Dummy { async fn setup(&mut self) { return; } @@ -65,10 +64,10 @@ impl<'a> Sensor<'a> for Dummy<'a> { } } -impl<'a> Stream for Dummy<'a> { - type Item = BoxFuture<'a, ()>; +impl Stream for Dummy { + type Item = BoxFuture<'static, ()>; fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - todo!() + Poll::Ready(Some(Box::pin(futures::future::ready(())))) } }