Skip to content

Commit

Permalink
feat: add MenuItemKind::id (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Aug 31, 2023
1 parent 9c4d6bb commit bce7540
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/menu-item-kind-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"muda": "patch"
---

Add `MenuItemKind::id` convenient method to get access to the inner kind id.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -267,6 +278,7 @@ pub(crate) enum MenuItemType {
Check,
Icon,
}

impl Default for MenuItemType {
fn default() -> Self {
Self::MenuItem
Expand Down

0 comments on commit bce7540

Please sign in to comment.