Skip to Content
Rust Programming By Example
book

Rust Programming By Example

by Guillaume Gomez, Antoni Boucher
January 2018
Beginner to intermediate
454 pages
10h 8m
English
Packt Publishing
Content preview from Rust Programming By Example

Syntax sugar to send a message to another relm widget

Sending a message to another widget with emit() is a bit verbose, so relm provides syntactic sugar for this case. Let's send a message to the playlist when the user clicks the remove button:

gtk::ToolButton {
    icon_widget: &new_icon("remove"),
    clicked => playlist@RemoveSong,
}

Here, we used the @ syntax to specify that the message will be sent to another widget. The part before the @ is the receiver widget, while the part after this character is the message. So, this code means that whenever the user clicks the remove button, send the RemoveSong message to the playlist widget.

Let's handle this message in the Paylist::update() method:

#[widget]
impl Widget for Playlist {
    fn update(&mut ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Rust Programming Cookbook

Rust Programming Cookbook

Claus Matzinger
Rust Web Programming

Rust Web Programming

Maxwell Flitton

Publisher Resources

ISBN: 9781788390637Supplemental Content