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