pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ErrorKind {
UnsupportedPlatform,
SessionLimit,
InvalidSessionKey,
Cancelled,
AccessDenied,
InvalidInput,
DirectoryNotSupported,
TooManyResources,
CallbackInUse,
DataChanged,
MalformedOsData,
RebootRequired,
ShutdownIncomplete,
RestartIncomplete,
OperationOutOfSequence,
RegistryUnavailable,
FilterNotFound,
OutOfMemory,
ApplicationRestartInUse,
AsyncWorkerUnavailable,
SessionEnded,
Os,
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[error("{message}")]
pub struct Error {
kind: ErrorKind,
raw_os_error: Option<u32>,
raw_hresult: Option<i32>,
message: String,
}
impl Error {
#[must_use]
pub const fn kind(&self) -> ErrorKind {
self.kind
}
#[must_use]
pub const fn raw_os_error(&self) -> Option<u32> {
self.raw_os_error
}
#[must_use]
pub const fn raw_hresult(&self) -> Option<i32> {
self.raw_hresult
}
pub(crate) fn new(
kind: ErrorKind,
raw_os_error: Option<u32>,
message: impl Into<String>,
) -> Self {
Self {
kind,
raw_os_error,
raw_hresult: None,
message: message.into(),
}
}
pub(crate) fn from_hresult(kind: ErrorKind, hresult: i32, message: impl Into<String>) -> Self {
Self {
kind,
raw_os_error: None,
raw_hresult: Some(hresult),
message: message.into(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, thiserror::Error)]
#[error("a session key must contain exactly 32 ASCII hexadecimal characters")]
pub struct ParseSessionKeyError;