Skip to main content

wslplugins_rs/user_distribution_id/
parse_error.rs

1use thiserror::Error;
2use windows_core::HRESULT;
3
4#[derive(Debug, Error)]
5pub enum ParseError {
6    #[error("Windows error: HRESULT={0}")]
7    Windows(HRESULT),
8
9    #[cfg(feature = "uuid")]
10    #[error("UUID parsing error: {0}")]
11    UUID(#[from] uuid::Error),
12}
13
14impl From<windows_core::Error> for ParseError {
15    #[inline]
16    fn from(value: windows_core::Error) -> Self {
17        Self::Windows(value.code())
18    }
19}
20#[cfg(feature = "uuid")]
21#[expect(
22    clippy::unreadable_literal,
23    reason = "It's the natural Microsoft error format"
24)]
25pub const E_INVALIDARG: windows_core::HRESULT = HRESULT(0x80070057_u32.cast_signed());
26impl From<ParseError> for windows_core::HRESULT {
27    #[inline]
28    fn from(value: ParseError) -> Self {
29        match value {
30            ParseError::Windows(hresult) => hresult,
31            #[cfg(feature = "uuid")]
32            ParseError::UUID(_) => E_INVALIDARG,
33        }
34    }
35}
36
37impl From<ParseError> for windows_core::Error {
38    #[inline]
39    fn from(value: ParseError) -> Self {
40        Self::from_hresult(value.into())
41    }
42}