Open antoyo opened 4 years ago
Is there a workaround for this issue?
Maybe something like this:
view! {
gtk::Label {
text: {
let counter = &self.model.counter;
&format!("{}", counter)
},
},
}
This seems non-trivial to fix and the above workaround doesn't work.
As macro arguments can be anything, even invalid Rust code, it makes it very hard to actually parse them to find usage of self.model
.
Does anyone have any solution to this problem?
What macros do you use in this context?
Maybe we could only support a limited set of macros, like format!
.
A minimalist example to reproduce this bug:
use gtk::GtkWindowExt;
use relm::Widget;
#[relm_derive::widget]
impl Widget for Win {
fn model() -> String {
"#189".to_string()
}
fn update(&mut self, _: ()) {
}
view! {
gtk::Window {
title: &format!("{}", self.model),
}
}
}
fn main() {
Win::run(()).expect("Win::run failed");
}
Using __relm_model
works fine.
Some ideas:
__relm_model
to model
;self.model
and replace it by __relm_model
;view!
:
view!(model) {
gtk::Window {
title: &format!("{}", model),
}
}
I like the second one, but it maybe not the easier…
If we were to choose the second option, how would that be implemented?
By iterating over all the tokens in the macro and replacing the appropriate sequence of tokens (self
, .
, models
) by __relm_model
everywhere?