Skip to main content

dope_sys/thread/affinity/
raw.rs

1/// A logical CPU observed in the calling thread's affinity mask.
2///
3/// Native discovery produces these values, so carrying a `Cpu` preserves
4/// the discovery proof through process layout and thread binding.
5#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
6#[repr(transparent)]
7pub struct Cpu(u16);
8
9impl Cpu {
10    /// # Safety
11    /// `raw` must have been observed in the current platform's CPU affinity set.
12    pub const unsafe fn new(raw: u16) -> Self {
13        Self(raw)
14    }
15
16    pub const fn raw(self) -> u16 {
17        self.0
18    }
19}
20
21impl From<Cpu> for u64 {
22    fn from(cpu: Cpu) -> Self {
23        u64::from(cpu.0)
24    }
25}