I know this type of question has been asked a thousand times in here, but I still can't work out why it happens here.
Building an interface in ICED.
Working code to build a button instance:
pub(crate) fn view(&self) -> Container<Message, Theme, Renderer> {
let w = Length::from(10.0);
let h = Length::from(10.0);
let b_one = make_button(w, h, "1");
container(b_one) // returns here
}
fn make_button(width: Length, height: Length, name: &str) -> Element<Message> {
let container = Container::new(name)
.align_x(Horizontal::Center)
.align_y(Vertical::Center)
.clip(false);
Button::new(container)
.width(width)
.height(height)
.style(|_theme, status| {
crate::ui::window::get_style(status)
})
.on_press(Message::Char(name.to_string())))
.into()
}
But if I add a builder like so
struct Builder {
w : Length,
h : Length,
}
impl Builder {
fn make(&self) -> Element<Message> {
make_button(self.w, self.h, "1")
}
}
and use it to to make the button
let b_one = Builder{w, h}.make();
etc
Then I get the well know cannot return value referencing temporary value
.