Answer#
iced uses the Elm architecture. There are three pieces:
- State: an ordinary struct (
Counter). - Message: an enum of everything that can happen (
Increment,Decrement). - update and view:
updateis the only place that changes the state;viewis a function from the state to the widgets, called again after each change.
[dependencies]
iced = "0.13"use iced::widget::{button, column, text};
use iced::Element;
#[derive(Default)]
struct Counter {
value: i32,
}
#[derive(Debug, Clone)]
enum Message {
Increment,
Decrement,
}
impl Counter {
// All changes happen here, in response to a message.
fn update(&mut self, message: Message) {
match message {
Message::Increment => self.value += 1,
Message::Decrement => self.value -= 1,
}
}
// The view is a function of the state; it only describes the window.
fn view(&self) -> Element<'_, Message> {
column![
button("+").on_press(Message::Increment),
text(self.value).size(40),
button("-").on_press(Message::Decrement),
]
.padding(20)
.into()
}
}
fn main() -> iced::Result {
iced::run("Counter", Counter::update, Counter::view)
}This compiled with cargo check on Windows 11 using iced 0.13. It was not run.
The benefit of the structure: every change to the state goes through one match, so the list of things the program can do is the Message enum. Work that takes time (reading a file, a request) is started from update and comes back as another message.
Common mistakes#
- Following an example written for another iced version. Entry points such as
iced::runand the way the title is set have differed between releases; check the version of the example against yourCargo.toml. - Changing state inside
view.viewtakes&selfon purpose.
Related questions#
Can iced do more than buttons and text?#
Yes: the iced::widget module has more widgets, and the iced repository has an examples folder. This thread compiled only the counter.
Sources#
- iced README: https://github.com/iced-rs/iced (read 2026-12-05)
- iced documentation: https://docs.rs/iced/0.13/iced/ (read 2026-12-05)