proc_heim/process/model/
id.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use std::fmt::Display;

use uuid::Uuid;

/// Type representing an ID of spawned process. Uses `UUID` internally.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ProcessId {
    inner: Uuid,
}

impl ProcessId {
    pub(crate) fn random() -> Self {
        Self {
            inner: Uuid::new_v4(),
        }
    }
}

impl Display for ProcessId {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(&self.inner.to_string())
    }
}

impl From<Uuid> for ProcessId {
    fn from(inner: Uuid) -> Self {
        Self { inner }
    }
}

impl AsRef<Uuid> for ProcessId {
    fn as_ref(&self) -> &Uuid {
        &self.inner
    }
}