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 clipboard;
13pub mod font;
14pub mod image;
15pub mod keyboard;
16pub mod system;
17pub mod task;
18pub mod user_interface;
19pub mod widget;
20pub mod window;
21
22pub use iced_core as core;
23pub use iced_futures as futures;
24
25pub use task::Task;
26pub use user_interface::UserInterface;
27pub use window::Window;
28
29use crate::futures::futures::channel::oneshot;
30
31use std::borrow::Cow;
32use std::fmt;
33
34pub enum Action<T> {
36 Output(T),
38
39 LoadFont {
41 bytes: Cow<'static, [u8]>,
43 channel: oneshot::Sender<Result<(), font::Error>>,
45 },
46
47 Widget(Box<dyn core::widget::Operation>),
49
50 Clipboard(clipboard::Action),
52
53 Window(window::Action),
55
56 System(system::Action),
58
59 Image(image::Action),
61
62 Reload,
64
65 Exit,
70}
71
72impl<T> Action<T> {
73 pub fn widget(operation: impl core::widget::Operation + 'static) -> Self {
75 Self::Widget(Box::new(operation))
76 }
77
78 fn output<O>(self) -> Result<T, Action<O>> {
79 match self {
80 Action::Output(output) => Ok(output),
81 Action::LoadFont { bytes, channel } => Err(Action::LoadFont { bytes, channel }),
82 Action::Widget(operation) => Err(Action::Widget(operation)),
83 Action::Clipboard(action) => Err(Action::Clipboard(action)),
84 Action::Window(action) => Err(Action::Window(action)),
85 Action::System(action) => Err(Action::System(action)),
86 Action::Image(action) => Err(Action::Image(action)),
87 Action::Reload => Err(Action::Reload),
88 Action::Exit => Err(Action::Exit),
89 }
90 }
91}
92
93impl<T> fmt::Debug for Action<T>
94where
95 T: fmt::Debug,
96{
97 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
98 match self {
99 Action::Output(output) => write!(f, "Action::Output({output:?})"),
100 Action::LoadFont { .. } => {
101 write!(f, "Action::LoadFont")
102 }
103 Action::Widget { .. } => {
104 write!(f, "Action::Widget")
105 }
106 Action::Clipboard(action) => {
107 write!(f, "Action::Clipboard({action:?})")
108 }
109 Action::Window(_) => write!(f, "Action::Window"),
110 Action::System(action) => write!(f, "Action::System({action:?})"),
111 Action::Image(_) => write!(f, "Action::Image"),
112 Action::Reload => write!(f, "Action::Reload"),
113 Action::Exit => write!(f, "Action::Exit"),
114 }
115 }
116}
117
118pub fn exit<T>() -> Task<T> {
123 task::effect(Action::Exit)
124}