wezterm_blob_leases/
lease_id.rs1use std::sync::LazyLock;
2use uuid::Uuid;
3
4#[derive(Clone, Copy, Eq, PartialEq, Debug)]
6pub struct LeaseId {
7 uuid: Uuid,
8 pid: u32,
9}
10
11impl std::fmt::Display for LeaseId {
12 fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
13 write!(fmt, "lease:pid={},{}", self.pid, self.uuid.hyphenated())
14 }
15}
16
17fn get_mac_address() -> [u8; 6] {
18 match mac_address::get_mac_address() {
19 Ok(Some(addr)) => addr.bytes(),
20 _ => {
21 let mut mac = [0u8; 6];
22 getrandom::fill(&mut mac).ok();
23 mac
24 }
25 }
26}
27
28impl LeaseId {
29 pub fn new() -> Self {
30 static MAC: LazyLock<[u8; 6]> = LazyLock::new(get_mac_address);
31 let uuid = Uuid::now_v1(&*MAC);
32 let pid = std::process::id();
33 Self { uuid, pid }
34 }
35
36 pub fn pid(&self) -> u32 {
37 self.pid
38 }
39}