1#![doc = include_str!("../readme.md")]
2#![cfg(windows)]
3#![no_std]
4
5#[macro_use]
6extern crate alloc;
7
8use alloc::{string::String, vec::Vec};
9use core::ops::Deref;
10use core::ptr::{null, null_mut};
11
12mod bindings;
13use bindings::*;
14
15mod open_options;
16pub use open_options::OpenOptions;
17
18mod key;
19pub use key::Key;
20
21mod transaction;
22pub use transaction::Transaction;
23
24mod value;
25pub use value::Value;
26
27mod data;
28use data::Data;
29
30mod pcwstr;
31use pcwstr::*;
32
33mod key_iterator;
34pub use key_iterator::KeyIterator;
35
36mod value_iterator;
37pub use value_iterator::ValueIterator;
38
39mod r#type;
40pub use r#type::Type;
41
42pub use windows_result::Result;
43use windows_result::*;
44
45pub use windows_strings::HSTRING;
46use windows_strings::{PCWSTR, *};
47
48pub const CLASSES_ROOT: &Key = &Key(HKEY_CLASSES_ROOT);
50
51pub const CURRENT_CONFIG: &Key = &Key(HKEY_CURRENT_CONFIG);
53
54pub const CURRENT_USER: &Key = &Key(HKEY_CURRENT_USER);
56
57pub const LOCAL_MACHINE: &Key = &Key(HKEY_LOCAL_MACHINE);
59
60pub const USERS: &Key = &Key(HKEY_USERS);
62
63fn win32_error(result: u32) -> Result<()> {
64 if result == 0 {
65 Ok(())
66 } else {
67 Err(Error::from_hresult(HRESULT::from_win32(result)))
68 }
69}
70
71fn invalid_data() -> Error {
72 Error::from_hresult(HRESULT::from_win32(ERROR_INVALID_DATA))
73}
74
75fn from_le_bytes(ty: Type, from: &[u8]) -> Result<u64> {
76 match ty {
77 Type::U32 if from.len() == 4 => Ok(u32::from_le_bytes(from.try_into().unwrap()).into()),
78 Type::U64 if from.len() == 8 => Ok(u64::from_le_bytes(from.try_into().unwrap())),
79 _ => Err(invalid_data()),
80 }
81}
82
83fn as_bytes(value: &HSTRING) -> &[u8] {
85 unsafe { core::slice::from_raw_parts(value.as_ptr() as *const _, (value.len() + 1) * 2) }
86}