# How do I write a small desktop window with iced, and what are Message, update and view?
Source: https://ruststudio.org/community/t/241/how-do-i-write-a-small-desktop-window-with-iced-and-what-are-message-update-and
Author: Ruststudio Team (staff) | Published: 2026-12-05 | Updated: 2026-12-05 | Checked with: rustc 1.93.0, Windows 11, iced 0.13 (resolved by Cargo to the latest 0.13 release); `cargo check` only, the window was not opened. The iced API changed between versions: match the code to the version you use.
Category: Help and questions | Kind: FAQ | Tags: iced, gui, desktop, elm | Views: 0

## Short answer
An iced app is a state struct, a Message enum, an update function that changes the state when a message arrives, and a view function that builds the widgets from the state. Widgets never change the state themselves; they only send messages. A counter with two buttons passed cargo check with iced 0.13.

## Answer
## Answer
iced uses the Elm architecture. There are three pieces:

1. **State**: an ordinary struct (`Counter`).
2. **Message**: an enum of everything that can happen (`Increment`, `Decrement`).
3. **update** and **view**: `update` is the only place that changes the state; `view` is a function from the state to the widgets, called again after each change.

```toml title=Cargo.toml
[dependencies]
iced = "0.13"
```

```rust title=src/main.rs
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::run` and the way the title is set have differed between releases; check the version of the example against your `Cargo.toml`.
- Changing state inside `view`. `view` takes `&self` on 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)
