obkrnl/proc/
pid.rs

1use core::borrow::Borrow;
2use core::ffi::c_int;
3
4/// Unique identifier of a process.
5#[repr(transparent)]
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub struct Pid(c_int);
8
9impl Pid {
10    pub const KERNEL: Self = Self(0);
11    pub const IDLE: Self = Self(10);
12
13    /// Returns [`None`] if `v` is negative.
14    pub const fn new(v: c_int) -> Option<Self> {
15        if v >= 0 { Some(Self(v)) } else { None }
16    }
17}
18
19impl Borrow<c_int> for Pid {
20    fn borrow(&self) -> &c_int {
21        &self.0
22    }
23}
24
25impl PartialEq<c_int> for Pid {
26    fn eq(&self, other: &c_int) -> bool {
27        self.0 == *other
28    }
29}
30
31impl PartialEq<Pid> for c_int {
32    fn eq(&self, other: &Pid) -> bool {
33        *self == other.0
34    }
35}