Architecture
Iced is a cross-platform GUI library for Rust that follows The Elm Architecture pattern. This architecture provides a simple, type-safe, and predictable way to build user interfaces.The Elm Architecture Pattern
Iced splits user interfaces into four distinct concepts:This architecture is inspired by Elm, a functional programming language for building web applications.
Core Principles
Type Safety
Iced leverages Rust’s type system to its full extent. The connection between your state, messages, view, and update logic is enforced at compile time:view function returns an Element<Message>, ensuring that any messages produced by widgets match the messages expected by update.
Unidirectional Data Flow
Iced enforces a unidirectional data flow:This unidirectional flow makes your application’s behavior predictable and easier to reason about.
Running an Application
The simplest way to run an Iced application is with therun function:
- Simple
- Advanced
Runtime Behavior
When you run an Iced application, the runtime automatically:- Takes the result of your view logic and lays out its widgets
- Processes events from the system and produces messages for your update logic
- Draws the resulting user interface
- Repeats whenever state changes or events occur
Iced handles all the low-level details of window management, event handling, and rendering, allowing you to focus on your application logic.
Modular Ecosystem
Iced’s architecture is modular, consisting of several reusable components:Core Modules
- iced_core - Core types and traits (Element, Widget, etc.)
- iced_runtime - Platform-agnostic runtime for managing state
- iced_winit - Window management using winit
- iced_wgpu - GPU-accelerated renderer using wgpu
- iced_widget - Built-in widgets (buttons, text inputs, etc.)
- Use only the parts you need
- Integrate Iced into existing applications
- Create custom renderers or widget libraries
- Choose between GPU and software rendering
Next Steps
Now that you understand the architecture, dive deeper into each component:- State and Messages - Learn how to model your application’s data
- View and Update - Master the update-view cycle
- Elements and Widgets - Build your user interface
