Improves lifetimes to be more ergonomic

This commit is contained in:
Gregor Reitzenstein 2020-09-17 11:57:45 +02:00
parent 637490bd75
commit 267ff63016

View File

@ -20,8 +20,8 @@ impl Sensors {
} }
} }
pub type SensBox<'a> = Box<dyn Sensor<'a>>; pub type SensBox = Box<dyn Sensor>;
type Inner = HashMap<String, SensBox<'static>>; type Inner = HashMap<String, SensBox>;
// Implementing Sensors. // Implementing Sensors.
@ -35,13 +35,14 @@ type Inner = HashMap<String, SensBox<'static>>;
/// A sensor is anything that can forward an intent of an user to do something to bffh. /// 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 /// 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 /// they want to use or something like QRHello
pub trait Sensor<'a>: Stream<Item = BoxFuture<'a, ()>> { pub trait Sensor: Stream<Item = BoxFuture<'static, ()>> {
/// Setup the Sensor. /// Setup the Sensor.
/// ///
/// After this async function completes the Stream implementation should be able to generate /// After this async function completes the Stream implementation should be able to generate
/// futures when polled. /// futures when polled.
/// Implementations can rely on this function being polled to completeion before the stream /// Implementations can rely on this function being polled to completeion before the stream
/// is polled. /// is polled.
// TODO Is this sensible vs just having module-specific setup fns?
async fn setup(&mut self); async fn setup(&mut self);
/// Shutdown the sensor gracefully /// Shutdown the sensor gracefully
@ -51,11 +52,9 @@ pub trait Sensor<'a>: Stream<Item = BoxFuture<'a, ()>> {
async fn shutdown(&mut self); async fn shutdown(&mut self);
} }
struct Dummy<'a> { struct Dummy;
phantom: &'a std::marker::PhantomData<()>,
}
#[async_trait] #[async_trait]
impl<'a> Sensor<'a> for Dummy<'a> { impl Sensor for Dummy {
async fn setup(&mut self) { async fn setup(&mut self) {
return; return;
} }
@ -65,10 +64,10 @@ impl<'a> Sensor<'a> for Dummy<'a> {
} }
} }
impl<'a> Stream for Dummy<'a> { impl Stream for Dummy {
type Item = BoxFuture<'a, ()>; type Item = BoxFuture<'static, ()>;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> { fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
todo!() Poll::Ready(Some(Box::pin(futures::future::ready(()))))
} }
} }