Skip to content

Commit

Permalink
add Submenu::get and use PartialEq
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Aug 10, 2023
1 parent e30ffc5 commit 3fb8cf0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/tauri/src/menu/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,11 @@ impl<R: Runtime> Menu<R> {
}

/// Retrieves the menu item matching the given identifier.
pub fn get<I: Into<MenuId>>(&self, id: I) -> Option<MenuItemKind<R>> {
let id = id.into();
pub fn get<'a, I>(&self, id: &'a I) -> Option<MenuItemKind<R>>
where
I: ?Sized,
MenuId: PartialEq<&'a I>,
{
self
.items()
.unwrap_or_default()
Expand Down
13 changes: 13 additions & 0 deletions core/tauri/src/menu/submenu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,17 @@ impl<R: Runtime> Submenu<R> {
run_main_thread!(self, |self_: Self| self_.inner.set_as_help_menu_for_nsapp())?;
Ok(())
}

/// Retrieves the menu item matching the given identifier.
pub fn get<'a, I>(&self, id: &'a I) -> Option<MenuItemKind<R>>
where
I: ?Sized,
MenuId: PartialEq<&'a I>,
{
self
.items()
.unwrap_or_default()
.into_iter()
.find(|i| i.id() == &id)
}
}

0 comments on commit 3fb8cf0

Please sign in to comment.