Move OptionFuture to its own file
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		
							parent
							
								
									7aaab40e0b
								
							
						
					
					
						commit
						4c782addb7
					
				| @ -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()?; | ||||
|  | ||||
							
								
								
									
										37
									
								
								src/option_future.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/option_future.rs
									
									
									
									
									
										Normal file
									
								
							| @ -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<F>(#[pin] Option<F>); | ||||
| 
 | ||||
| impl<F: Future> Future for OptionFuture<F> { | ||||
|     type Output = Option<F::Output>; | ||||
| 
 | ||||
|     fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||||
|         match self.project().0.as_pin_mut() { | ||||
|             Some(x) => x.poll(cx).map(Some), | ||||
|             None => Poll::Ready(None), | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl<F> Deref for OptionFuture<F> { | ||||
|     type Target = Option<F>; | ||||
| 
 | ||||
|     fn deref(&self) -> &Self::Target { | ||||
|         &self.0 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl<T> From<Option<T>> for OptionFuture<T> { | ||||
|     fn from(option: Option<T>) -> Self { | ||||
|         OptionFuture(option) | ||||
|     } | ||||
| } | ||||
| @ -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<F>(#[pin] Option<F>); | ||||
| 
 | ||||
|     impl<F: Future> Future for OptionFuture<F> { | ||||
|         type Output = Option<F::Output>; | ||||
| 
 | ||||
|         fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||||
|             match self.project().0.as_pin_mut() { | ||||
|                 Some(x) => x.poll(cx).map(Some), | ||||
|                 None => Poll::Ready(None), | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     impl<F> Deref for OptionFuture<F> { | ||||
|         type Target = Option<F>; | ||||
| 
 | ||||
|         fn deref(&self) -> &Self::Target { | ||||
|             &self.0 | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     impl<T> From<Option<T>> for OptionFuture<T> { | ||||
|         fn from(option: Option<T>) -> Self { | ||||
|             OptionFuture(option) | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| use option_future::OptionFuture; | ||||
| 
 | ||||
| async fn runner_task( | ||||
|     interface: Arc<dyn SectionInterface + Sync>, | ||||
|     mut msg_recv: mpsc::Receiver<RunnerMsg>, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user