pub trait ActionName {
type Group: ActionGroupName;
type Target;
type State;
const NAME: &'static str;
// Provided method
fn action_name() -> String { ... }
}
Expand description
Define the name of an action.
Required Associated Constants§
Required Associated Types§
Sourcetype Group: ActionGroupName
type Group: ActionGroupName
The group of this action.
Provided Methods§
Sourcefn action_name() -> String
fn action_name() -> String
The full action name (group.action).
Examples found in repository?
examples/actions.rs (line 61)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
fn init(
_init: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let menu_model = gtk::gio::Menu::new();
menu_model.append(Some("Stateless"), Some(&ExampleAction::action_name()));
let model = Self { counter: 0 };
let widgets = view_output!();
let app = relm4::main_application();
app.set_accelerators_for_action::<ExampleAction>(&["<primary>W"]);
let action: RelmAction<ExampleAction> = RelmAction::new_stateless(move |_| {
println!("Statelesss action!");
sender.input(Msg::Increment);
});
let action2: RelmAction<ExampleU8Action> =
RelmAction::new_stateful_with_target_value(&0, |_, state, value| {
println!("Stateful action -> state: {state}, value: {value}");
*state += value;
});
let mut group = RelmActionGroup::<WindowActionGroup>::new();
group.add_action(action);
group.add_action(action2);
group.register_for_widget(&widgets.main_window);
ComponentParts { model, widgets }
}
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.