Skip to main content

windows_registry/
type.rs

1use super::*;
2
3/// The possible types that a registry value could have.
4#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
5pub enum Type {
6    /// A 32-bit unsigned integer value.
7    U32,
8
9    /// A 64-bit unsigned integer value.
10    U64,
11
12    /// A string value.
13    String,
14
15    /// A string value that may contain unexpanded environment variables.
16    ExpandString,
17
18    /// An array of string values.
19    MultiString,
20
21    /// An array u8 bytes.
22    Bytes,
23
24    /// An unknown type.
25    Other(u32),
26}
27
28impl From<u32> for Type {
29    fn from(ty: u32) -> Self {
30        match ty {
31            REG_DWORD => Self::U32,
32            REG_QWORD => Self::U64,
33            REG_SZ => Self::String,
34            REG_EXPAND_SZ => Self::ExpandString,
35            REG_MULTI_SZ => Self::MultiString,
36            REG_BINARY => Self::Bytes,
37            rest => Self::Other(rest),
38        }
39    }
40}
41
42impl From<Type> for u32 {
43    fn from(ty: Type) -> Self {
44        match ty {
45            Type::U32 => REG_DWORD,
46            Type::U64 => REG_QWORD,
47            Type::String => REG_SZ,
48            Type::ExpandString => REG_EXPAND_SZ,
49            Type::MultiString => REG_MULTI_SZ,
50            Type::Bytes => REG_BINARY,
51            Type::Other(other) => other,
52        }
53    }
54}