1#![allow(clippy::enum_variant_names)]
2use crate::accelerator::AcceleratorParseError;
3
4#[non_exhaustive]
5#[derive(Debug)]
6pub enum Error {
7 NotAChildOfThisMenu,
8 NotInitialized,
9 AlreadyInitialized,
10 AcceleratorParseError(AcceleratorParseError),
11}
12
13impl std::fmt::Display for Error {
14 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15 match self {
16 Error::NotAChildOfThisMenu => write!(
17 f,
18 "This menu item is not a child of this `Menu` or `Submenu`"
19 ),
20 Error::NotInitialized => write!(f, "This menu has not been initialized for this hwnd"),
21 Error::AlreadyInitialized => {
22 write!(f, "This menu has already been initialized for this hwnd")
23 }
24 Error::AcceleratorParseError(err) => write!(f, "{}", err),
25 }
26 }
27}
28
29impl std::error::Error for Error {
30 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
31 match self {
32 Error::AcceleratorParseError(err) => Some(err),
33 _ => None,
34 }
35 }
36}
37
38impl From<AcceleratorParseError> for Error {
39 fn from(err: AcceleratorParseError) -> Self {
40 Error::AcceleratorParseError(err)
41 }
42}
43
44pub type Result<T> = std::result::Result<T, Error>;