pub trait MenuAction:
Clone
+ Copy
+ Eq
+ PartialEq {
type Message;
// Required method
fn message(&self) -> Self::Message;
}
Expand description
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,
}
}
}
Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.