ember_os 0.1.3

A simple OS kernel implemented in rust, which has referenced https://os.phil-opp.com/
Documentation
use super::Task;
use alloc::collections::VecDeque;
use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};

pub struct SimpleExecutor {
  task_queue: VecDeque<Task>,
}

impl SimpleExecutor {
  pub fn new() -> SimpleExecutor {
    SimpleExecutor {
      task_queue: VecDeque::new(),
    }
  }

  pub fn spawn(&mut self, task: Task) {
    self.task_queue.push_back(task)
  }
}

impl Default for SimpleExecutor {
  fn default() -> Self {
    Self::new()
  }
}

impl SimpleExecutor {
  pub fn run(&mut self) {
    while let Some(mut task) = self.task_queue.pop_front() {
      let waker = dummy_waker();
      let mut context = Context::from_waker(&waker);
      match task.poll(&mut context) {
        Poll::Ready(()) => {} // task done
        Poll::Pending => self.task_queue.push_back(task),
      }
    }
  }
}

fn dummy_raw_waker() -> RawWaker {
  fn no_op(_: *const ()) {}
  fn clone(_: *const ()) -> RawWaker {
    dummy_raw_waker()
  }
  let vtable = &RawWakerVTable::new(clone, no_op, no_op, no_op);
  RawWaker::new(core::ptr::null::<()>(), vtable)
}

fn dummy_waker() -> Waker {
  unsafe { Waker::from_raw(dummy_raw_waker()) }
}