From bce7540bba0d26ae4e55b3e2d164f1579b58743a Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Thu, 31 Aug 2023 18:13:41 +0300 Subject: [PATCH] feat: add `MenuItemKind::id` (#113) --- .changes/menu-item-kind-id.md | 5 +++++ src/lib.rs | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .changes/menu-item-kind-id.md diff --git a/.changes/menu-item-kind-id.md b/.changes/menu-item-kind-id.md new file mode 100644 index 0000000..b1413ae --- /dev/null +++ b/.changes/menu-item-kind-id.md @@ -0,0 +1,5 @@ +--- +"muda": "patch" +--- + +Add `MenuItemKind::id` convenient method to get access to the inner kind id. diff --git a/src/lib.rs b/src/lib.rs index 349437a..524a2cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -166,6 +166,17 @@ pub enum MenuItemKind { } impl MenuItemKind { + /// Returns the id associated with this menu item. + pub fn id(&self) -> &MenuId { + match self { + MenuItemKind::MenuItem(i) => i.id(), + MenuItemKind::Submenu(i) => i.id(), + MenuItemKind::Predefined(i) => i.id(), + MenuItemKind::Check(i) => i.id(), + MenuItemKind::Icon(i) => i.id(), + } + } + /// Casts this item to a [`MenuItem`], and returns `None` if it wasn't. pub fn as_menuitem(&self) -> Option<&MenuItem> { match self { @@ -267,6 +278,7 @@ pub(crate) enum MenuItemType { Check, Icon, } + impl Default for MenuItemType { fn default() -> Self { Self::MenuItem