windows_registry/
type.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use super::*;

/// The possible types that a registry value could have.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Type {
    /// A 32-bit unsigned integer value.
    U32,

    /// A 64-bit unsigned integer value.
    U64,

    /// A string value.
    String,

    /// A string value that may contain unexpanded environment variables.
    ExpandString,

    /// An array of string values.
    MultiString,

    /// An array u8 bytes.
    Bytes,

    /// An unknown type.
    Other(u32),
}

impl From<u32> for Type {
    fn from(ty: u32) -> Self {
        match ty {
            REG_DWORD => Self::U32,
            REG_QWORD => Self::U64,
            REG_SZ => Self::String,
            REG_EXPAND_SZ => Self::ExpandString,
            REG_MULTI_SZ => Self::MultiString,
            REG_BINARY => Self::Bytes,
            rest => Self::Other(rest),
        }
    }
}

impl From<Type> for u32 {
    fn from(ty: Type) -> Self {
        match ty {
            Type::U32 => REG_DWORD,
            Type::U64 => REG_QWORD,
            Type::String => REG_SZ,
            Type::ExpandString => REG_EXPAND_SZ,
            Type::MultiString => REG_MULTI_SZ,
            Type::Bytes => REG_BINARY,
            Type::Other(other) => other,
        }
    }
}