1#![doc(
9 html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
10)]
11#![cfg_attr(docsrs, feature(doc_cfg))]
12pub mod backend;
13pub mod clipboard;
14pub mod font;
15pub mod image;
16pub mod keyboard;
17pub mod system;
18pub mod task;
19pub mod user_interface;
20pub mod widget;
21pub mod window;
22
23pub use iced_core as core;
24pub use iced_futures as futures;
25
26pub use task::Task;
27pub use user_interface::UserInterface;
28
29use crate::core::Event;
30
31use std::fmt;
32
33pub enum Action<T> {
35 Output(T),
37
38 Widget(Box<dyn core::widget::Operation>),
40
41 Clipboard(clipboard::Action),
43
44 Window(window::Action),
46
47 System(system::Action),
49
50 Font(font::Action),
52
53 Image(image::Action),
55
56 Backend(backend::Action),
58
59 Event {
61 window: core::window::Id,
63 event: Event,
65 },
66
67 Tick,
69
70 Reload,
72
73 Exit,
78}
79
80impl<T> Action<T> {
81 pub fn widget(operation: impl core::widget::Operation + 'static) -> Self {
83 Self::Widget(Box::new(operation))
84 }
85
86 fn output<O>(self) -> Result<T, Action<O>> {
87 match self {
88 Action::Output(output) => Ok(output),
89 Action::Widget(operation) => Err(Action::Widget(operation)),
90 Action::Clipboard(action) => Err(Action::Clipboard(action)),
91 Action::Window(action) => Err(Action::Window(action)),
92 Action::System(action) => Err(Action::System(action)),
93 Action::Font(action) => Err(Action::Font(action)),
94 Action::Image(action) => Err(Action::Image(action)),
95 Action::Backend(action) => Err(Action::Backend(action)),
96 Action::Event { window, event } => Err(Action::Event { window, event }),
97 Action::Tick => Err(Action::Tick),
98 Action::Reload => Err(Action::Reload),
99 Action::Exit => Err(Action::Exit),
100 }
101 }
102}
103
104impl<T> fmt::Debug for Action<T>
105where
106 T: fmt::Debug,
107{
108 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
109 match self {
110 Action::Output(output) => write!(f, "Action::Output({output:?})"),
111 Action::Widget { .. } => {
112 write!(f, "Action::Widget")
113 }
114 Action::Clipboard(action) => {
115 write!(f, "Action::Clipboard({action:?})")
116 }
117 Action::Window(_) => write!(f, "Action::Window"),
118 Action::System(action) => write!(f, "Action::System({action:?})"),
119 Action::Font(action) => {
120 write!(f, "Action::Font({action:?})")
121 }
122 Action::Image(action) => write!(f, "Action::Image({action:?})"),
123 Action::Backend(action) => write!(f, "Action::Backend({action:?})"),
124 Action::Event { window, event } => write!(
125 f,
126 "Action::Event {{ window: {window:?}, event: {event:?} }}"
127 ),
128 Action::Tick => write!(f, "Action::Tick"),
129 Action::Reload => write!(f, "Action::Reload"),
130 Action::Exit => write!(f, "Action::Exit"),
131 }
132 }
133}
134
135pub fn exit<T>() -> Task<T> {
140 task::effect(Action::Exit)
141}