diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/src/menu.rs | 40 | 
1 files changed, 36 insertions, 4 deletions
| diff --git a/core/src/menu.rs b/core/src/menu.rs index fe770216..52186140 100644 --- a/core/src/menu.rs +++ b/core/src/menu.rs @@ -4,11 +4,17 @@ use crate::keyboard::Hotkey;  /// Menu representation.  ///  /// This can be used by `shell` implementations to create a menu. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)]  pub struct Menu<Message> {      entries: Vec<Entry<Message>>,  } +impl<Message> PartialEq for Menu<Message> { +    fn eq(&self, other: &Self) -> bool { +        self.entries == other.entries +    } +} +  impl<Message> Menu<Message> {      /// Creates an empty [`Menu`].      pub fn new() -> Self { @@ -27,13 +33,13 @@ impl<Message> Menu<Message> {      }      /// Returns a [`MenuEntry`] iterator. -    pub fn iter(self) -> impl Iterator<Item = Entry<Message>> { -        self.entries.into_iter() +    pub fn iter(&self) -> impl Iterator<Item = &Entry<Message>> { +        self.entries.iter()      }  }  /// Represents one of the possible entries used to build a [`Menu`]. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)]  pub enum Entry<Message> {      /// Item for a [`Menu`]      Item { @@ -82,3 +88,29 @@ impl<Message> Entry<Message> {          Entry::Dropdown { content, submenu }      }  } + +impl<Message> PartialEq for Entry<Message> { +    fn eq(&self, other: &Self) -> bool { +        match (self, other) { +            ( +                Entry::Item { +                    content, hotkey, .. +                }, +                Entry::Item { +                    content: other_content, +                    hotkey: other_hotkey, +                    .. +                }, +            ) => content == other_content && hotkey == other_hotkey, +            ( +                Entry::Dropdown { content, submenu }, +                Entry::Dropdown { +                    content: other_content, +                    submenu: other_submenu, +                }, +            ) => content == other_content && submenu == other_submenu, +            (Entry::Separator, Entry::Separator) => true, +            _ => false, +        } +    } +} | 
