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

Other methods

This will require two new methods in the impl Widget:

#[widget]
impl Widget for App {
    // …

    fn set_current_time(&mut self, time: u64) {
        self.model.current_time = time;
        self.model.adjustment.set_value(time as f64);
    }

    fn set_play_icon(&self, icon: &str) {
        self.model.play_image.set_from_file(format!("assets/{}.png", icon));
    }
}

But these methods have nothing to do with a Widget, so why are we allowed to add custom methods in a trait implementation? Well, the #[widget] attribute will take these methods and move them to a separate impl App where they belong. But why do we want to do this instead of placing them ourselves? That's because relm analyzes the assignments to the model attributes in the methods in the implementation decorated ...

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