1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/// `MenuAction` is a trait that represents an action in a menu.
///
/// It is used to define the behavior of menu items when they are activated.
/// Each menu item can have a unique action associated with it.
///
/// This trait is generic over a type `Message` which is the type of message
/// that will be produced when the action is triggered.
///
/// # Example
///
/// ```
/// use cosmic::widget::menu::action::MenuAction;
/// use cosmic::widget::segmented_button::Entity;
///
/// #[derive(Clone, Copy, Eq, PartialEq)]
/// enum MyMessage {
///     Open,
///     Save,
///     Quit,
/// }
///
/// #[derive(Clone, Copy, Eq, PartialEq)]
/// enum MyAction {
///     Open,
///     Save,
///     Quit,
/// }
///
/// impl MenuAction for MyAction {
///     type Message = MyMessage;
///
///     fn message(&self) -> Self::Message {
///         match self {
///             MyAction::Open => MyMessage::Open,
///             MyAction::Save => MyMessage::Save,
///             MyAction::Quit => MyMessage::Quit,
///         }
///     }
/// }
/// ```
pub trait MenuAction: Clone + Copy + Eq + PartialEq {
    /// The type of message that will be produced when the action is triggered.
    type Message;

    /// Returns a message of type `Self::Message` when the action is triggered.
    ///
    /// # Returns
    ///
    /// * `Self::Message` - The message that is produced when the action is triggered.
    fn message(&self) -> Self::Message;
}