mod.rs
1 use core::{future::Future, pin::Pin}; 2 use alloc::boxed::Box; 3 use core::task::{Context, Poll}; 4 use core::sync::atomic::{AtomicU64, Ordering}; 5 6 pub mod simple_executor; 7 pub mod keyboard; 8 pub mod executor; 9 10 pub struct Task { 11 id: TaskId, 12 future: Pin<Box<dyn Future<Output = ()>>>, 13 } 14 15 impl Task { 16 pub fn new(future: impl Future<Output = ()> + 'static) -> Task { 17 Task { 18 id: TaskId::new(), 19 future: Box::pin(future), 20 } 21 } 22 23 fn poll(&mut self, context: &mut Context) -> Poll<()> { 24 self.future.as_mut().poll(context) 25 } 26 } 27 28 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] 29 struct TaskId(u64); 30 31 impl TaskId { 32 fn new() -> Self { 33 static NEXT_ID: AtomicU64 = AtomicU64::new(0); 34 TaskId(NEXT_ID.fetch_add(1, Ordering::Relaxed)) 35 } 36 }