Using relm on stable Rust
In this whole chapter, we used Rust nightly to be able to use custom attributes, which are currently unstable. The #[widget] attribute provided by relm provides many advantages:
- Declarative view
- Data bindings
- Less typing
So it would be nice to be able to use a similar syntax on stable that provides the same advantages. And it is possible to do so, by using the relm_widget! macro. We'll rewrite the App widget to use this macro:
relm_widget! { impl Widget for App { fn init_view(&mut self) { self.toolbar.show_all(); } fn model() -> Model { Model { adjustment: Adjustment::new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0), cover_pixbuf: None, cover_visible: false, current_duration: 0, current_time: 0, play_image: new_icon(PLAY_ICON), stopped: true, } } fn open(&self) { // … ...