1use windows::core::PCSTR;
2
3#[derive(Debug, Clone, Eq, PartialEq, Hash)]
10pub enum Id {
11 Integer(u16),
12 Text(String),
13}
14
15impl From<PCSTR> for Id {
17 fn from(v: PCSTR) -> Self {
18 let pv = v.0 as usize;
19 if pv < 0xffff {
20 Id::Integer(pv as u16)
21 } else {
22 unsafe { Id::Text(v.display().to_string()) }
23 }
24 }
25}
26
27impl From<u16> for Id {
29 fn from(v: u16) -> Self {
30 Id::Integer(v)
31 }
32}
33
34impl Into<PCSTR> for Id {
37 fn into(self) -> PCSTR {
38 match self {
39 Id::Integer(id) => PCSTR(id as *const u8),
40 Id::Text(text) => PCSTR::from_raw(format!("{text}\0").as_ptr()),
41 }
42 }
43}
44
45impl Into<PCSTR> for &Id {
46 fn into(self) -> PCSTR {
47 match self {
48 Id::Integer(id) => PCSTR(*id as *const u8),
49 Id::Text(text) => PCSTR::from_raw(format!("{text}\0").as_ptr()),
50 }
51 }
52}