1#![doc(
9 html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
10)]
11#![cfg_attr(docsrs, feature(doc_auto_cfg))]
12pub mod clipboard;
13pub mod font;
14pub mod keyboard;
15pub mod system;
16pub mod task;
17pub mod user_interface;
18pub mod widget;
19pub mod window;
20
21pub use iced_core as core;
22pub use iced_debug as debug;
23pub use iced_futures as futures;
24
25pub use task::Task;
26pub use user_interface::UserInterface;
27
28use crate::futures::futures::channel::oneshot;
29
30use std::borrow::Cow;
31use std::fmt;
32
33pub enum Action<T> {
35 Output(T),
37
38 LoadFont {
40 bytes: Cow<'static, [u8]>,
42 channel: oneshot::Sender<Result<(), font::Error>>,
44 },
45
46 Widget(Box<dyn core::widget::Operation>),
48
49 Clipboard(clipboard::Action),
51
52 Window(window::Action),
54
55 System(system::Action),
57
58 Reload,
60
61 Exit,
66}
67
68impl<T> Action<T> {
69 pub fn widget(operation: impl core::widget::Operation + 'static) -> Self {
71 Self::Widget(Box::new(operation))
72 }
73
74 fn output<O>(self) -> Result<T, Action<O>> {
75 match self {
76 Action::Output(output) => Ok(output),
77 Action::LoadFont { bytes, channel } => {
78 Err(Action::LoadFont { bytes, channel })
79 }
80 Action::Widget(operation) => Err(Action::Widget(operation)),
81 Action::Clipboard(action) => Err(Action::Clipboard(action)),
82 Action::Window(action) => Err(Action::Window(action)),
83 Action::System(action) => Err(Action::System(action)),
84 Action::Reload => Err(Action::Reload),
85 Action::Exit => Err(Action::Exit),
86 }
87 }
88}
89
90impl<T> fmt::Debug for Action<T>
91where
92 T: fmt::Debug,
93{
94 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
95 match self {
96 Action::Output(output) => write!(f, "Action::Output({output:?})"),
97 Action::LoadFont { .. } => {
98 write!(f, "Action::LoadFont")
99 }
100 Action::Widget { .. } => {
101 write!(f, "Action::Widget")
102 }
103 Action::Clipboard(action) => {
104 write!(f, "Action::Clipboard({action:?})")
105 }
106 Action::Window(_) => write!(f, "Action::Window"),
107 Action::System(action) => write!(f, "Action::System({action:?})"),
108 Action::Reload => write!(f, "Action::Reload"),
109 Action::Exit => write!(f, "Action::Exit"),
110 }
111 }
112}
113
114pub fn exit<T>() -> Task<T> {
119 task::effect(Action::Exit)
120}