Skip to main content

compio_driver/
cancel.rs

1use crate::{
2    Key, OpCode,
3    key::{ErasedKey, WeakKey},
4};
5
6/// A type-erased cancel token.
7#[derive(Debug, Clone, PartialEq, Eq, Hash)]
8#[repr(transparent)]
9pub struct Cancel(WeakKey);
10
11impl Cancel {
12    /// Check if this cancel token cancels the given key.
13    pub fn cancels<T: OpCode>(&self, key: &Key<T>) -> bool {
14        self.0.as_ptr() as usize == key.as_raw()
15    }
16
17    pub(crate) fn new<T: OpCode>(key: &Key<T>) -> Self {
18        Self(key.downgrade())
19    }
20
21    pub(crate) fn upgrade(&self) -> Option<ErasedKey> {
22        self.0.upgrade()
23    }
24}