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 overlay;
16pub mod system;
17pub mod task;
18pub mod user_interface;
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::core::widget;
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 widget::Operation>),
49
50 Clipboard(clipboard::Action),
52
53 Window(window::Action),
55
56 System(system::Action),
58
59 Exit,
64}
65
66impl<T> Action<T> {
67 pub fn widget(operation: impl widget::Operation + 'static) -> Self {
69 Self::Widget(Box::new(operation))
70 }
71
72 fn output<O>(self) -> Result<T, Action<O>> {
73 match self {
74 Action::Output(output) => Ok(output),
75 Action::LoadFont { bytes, channel } => {
76 Err(Action::LoadFont { bytes, channel })
77 }
78 Action::Widget(operation) => Err(Action::Widget(operation)),
79 Action::Clipboard(action) => Err(Action::Clipboard(action)),
80 Action::Window(action) => Err(Action::Window(action)),
81 Action::System(action) => Err(Action::System(action)),
82 Action::Exit => Err(Action::Exit),
83 }
84 }
85}
86
87impl<T> fmt::Debug for Action<T>
88where
89 T: fmt::Debug,
90{
91 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
92 match self {
93 Action::Output(output) => write!(f, "Action::Output({output:?})"),
94 Action::LoadFont { .. } => {
95 write!(f, "Action::LoadFont")
96 }
97 Action::Widget { .. } => {
98 write!(f, "Action::Widget")
99 }
100 Action::Clipboard(action) => {
101 write!(f, "Action::Clipboard({action:?})")
102 }
103 Action::Window(_) => write!(f, "Action::Window"),
104 Action::System(action) => write!(f, "Action::System({action:?})"),
105 Action::Exit => write!(f, "Action::Exit"),
106 }
107 }
108}
109
110pub fn exit<T>() -> Task<T> {
115 task::effect(Action::Exit)
116}