mod encoding;
mod winhttp;
pub(crate) use encoding::*;
pub(crate) use winhttp::*;
use crate::Error;
use windows_sys::Win32::Foundation::GetLastError;
fn last_win32_error() -> Error {
let code = unsafe { GetLastError() };
Error::from_win32(code)
}
fn check_win32_bool(result: i32) -> Result<(), Error> {
if result != 0 {
Ok(())
} else {
Err(last_win32_error())
}
}
fn to_wide(s: &str) -> Vec<u16> {
s.encode_utf16().chain(std::iter::once(0)).collect()
}
#[expect(
clippy::cast_possible_truncation,
reason = "compile-time assert above bounds size_of::<T>() to u32::MAX"
)]
pub(crate) const fn dword_size_of<T>() -> u32 {
const {
assert!(std::mem::size_of::<T>() <= u32::MAX as usize, "size_of::<T>() exceeds u32::MAX");
};
std::mem::size_of::<T>() as u32
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn to_wide_table() {
let cases: &[(&str, &[u16], &str)] = &[
("", &[0], "empty"),
("abc", &[b'a' as u16, b'b' as u16, b'c' as u16, 0], "ascii"),
("\u{1F600}", &[0xD83D, 0xDE00, 0], "non-BMP surrogate pair"),
];
for &(input, expected, label) in cases {
let result = to_wide(input);
assert_eq!(result, expected, "to_wide: {label}");
}
}
}