Skip to main content

compio_runtime/future/
mod.rs

1//! Future combinators.
2
3mod personality;
4use compio_driver::Extra;
5pub use personality::*;
6
7#[non_exhaustive]
8#[derive(Clone, Debug, Default)]
9pub(crate) struct Ext {
10    personality: Option<u16>,
11}
12
13impl Ext {
14    pub fn new() -> Self {
15        Self::default()
16    }
17
18    pub fn with_personality(self, personality: u16) -> Self {
19        Self {
20            personality: Some(personality),
21            ..self
22        }
23    }
24
25    pub fn set_personality(&mut self, personality: u16) {
26        self.personality = Some(personality);
27    }
28
29    pub fn set_extra(&self, extra: &mut Extra) -> bool {
30        let mut changed = false;
31        if let Some(personality) = self.personality {
32            extra.set_personality(personality);
33            changed = true;
34        }
35        changed
36    }
37}
38
39/// Extension trait for futures.
40pub trait FutureExt {
41    /// Sets the personality for this future.
42    fn with_personality(self, personality: u16) -> WithPersonality<Self>
43    where
44        Self: Sized,
45    {
46        WithPersonality::new(self, personality)
47    }
48}