dope_runtime/executor/raw/
dispatch.rs1use std::{mem, pin};
2
3use dope_core::{
4 driver::{self, schedule},
5 io,
6};
7
8use crate::executor;
9
10#[must_use]
12pub struct Dispatch<'app, 'driver, 'turn, 'd, R> {
13 app: pin::Pin<&'app mut R>,
14 drive: executor::raw::Drive<'driver, 'turn, 'd>,
15 event: io::Event<'d>,
16}
17
18impl<'app, 'driver, 'turn, 'd, R> Dispatch<'app, 'driver, 'turn, 'd, R> {
19 pub const fn new(
21 app: pin::Pin<&'app mut R>,
22 event: io::Event<'d>,
23 turn: schedule::Turn<'turn, 'd>,
24 driver: driver::Context<'driver, 'd>,
25 ) -> Self {
26 Self {
27 app,
28 drive: executor::raw::Drive { turn, driver },
29 event,
30 }
31 }
32
33 pub fn into_event(self) -> io::Event<'d> {
34 self.event
35 }
36
37 pub fn into_parts(
38 self,
39 ) -> (
40 pin::Pin<&'app mut R>,
41 io::Event<'d>,
42 schedule::Turn<'turn, 'd>,
43 driver::Context<'driver, 'd>,
44 ) {
45 (self.app, self.event, self.drive.turn, self.drive.driver)
46 }
47}
48
49const fn assert_layout() {
50 type Call<'a> = Dispatch<'a, 'a, 'a, 'a, ()>;
51 type Drive<'a> = executor::raw::Drive<'a, 'a, 'a>;
52
53 assert!(
54 mem::size_of::<Call<'static>>()
55 == mem::size_of::<Drive<'static>>()
56 + mem::size_of::<io::Event<'static>>()
57 + mem::size_of::<pin::Pin<&'static mut ()>>()
58 );
59 assert!(mem::align_of::<Call<'static>>() == mem::align_of::<usize>());
60}
61
62const _: () = assert_layout();