diff --git a/src/main.rs b/src/main.rs index d0ab86f..608fcf2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use tracing_subscriber::EnvFilter; mod db; mod migrations; mod model; +mod option_future; mod section_interface; mod section_runner; #[cfg(test)] @@ -34,8 +35,7 @@ fn main() -> Result<()> { tracing_subscriber::fmt() .with_ansi(true) .with_env_filter( - EnvFilter::try_from_default_env() - .unwrap_or_else(|_| EnvFilter::new("info")), + EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")), ) .init(); color_eyre::install()?; diff --git a/src/option_future.rs b/src/option_future.rs new file mode 100644 index 0000000..1f957b9 --- /dev/null +++ b/src/option_future.rs @@ -0,0 +1,37 @@ +use pin_project::pin_project; +use std::{ + future::Future, + ops::Deref, + pin::Pin, + task::{Context, Poll}, +}; + +#[pin_project] +#[derive(Debug, Clone)] +#[must_use = "futures do nothing unless you `.await` or poll them"] +pub struct OptionFuture(#[pin] Option); + +impl Future for OptionFuture { + type Output = Option; + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + match self.project().0.as_pin_mut() { + Some(x) => x.poll(cx).map(Some), + None => Poll::Ready(None), + } + } +} + +impl Deref for OptionFuture { + type Target = Option; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl From> for OptionFuture { + fn from(option: Option) -> Self { + OptionFuture(option) + } +} diff --git a/src/section_runner.rs b/src/section_runner.rs index 0813e70..c92e2c1 100644 --- a/src/section_runner.rs +++ b/src/section_runner.rs @@ -1,4 +1,5 @@ use crate::model::SectionRef; +use crate::option_future::OptionFuture; use crate::section_interface::SectionInterface; use mpsc::error::SendError; use std::{ @@ -166,48 +167,6 @@ impl SecRun { } } -mod option_future { - use pin_project::pin_project; - use std::{ - future::Future, - ops::Deref, - pin::Pin, - task::{Context, Poll}, - }; - - #[pin_project] - #[derive(Debug, Clone)] - #[must_use = "futures do nothing unless you `.await` or poll them"] - pub struct OptionFuture(#[pin] Option); - - impl Future for OptionFuture { - type Output = Option; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - match self.project().0.as_pin_mut() { - Some(x) => x.poll(cx).map(Some), - None => Poll::Ready(None), - } - } - } - - impl Deref for OptionFuture { - type Target = Option; - - fn deref(&self) -> &Self::Target { - &self.0 - } - } - - impl From> for OptionFuture { - fn from(option: Option) -> Self { - OptionFuture(option) - } - } -} - -use option_future::OptionFuture; - async fn runner_task( interface: Arc, mut msg_recv: mpsc::Receiver,