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