1
- //! Create iced applications out of simple functions.
2
- //!
3
- //! You can use this API to create and run iced applications
4
- //! step by step—without coupling your logic to a trait
5
- //! or a specific type.
6
- //!
7
- //! This API is meant to be a more convenient—although less
8
- //! powerful—alternative to the [`Application`] traits.
9
- //!
10
- //! [`Sandbox`]: crate::Sandbox
11
1
//!
12
2
//! # Example
13
3
//! ```no_run
14
4
//! use iced::widget::{button, column, text, Column};
15
5
//! use iced::Theme;
16
6
//!
17
7
//! pub fn main() -> iced::Result {
18
- //! iced::application ("A counter", update, view)
8
+ //! iced::program ("A counter", update, view)
19
9
//! .theme(|_| Theme::Dark)
20
10
//! .centered()
21
11
//! .run()
@@ -53,7 +43,7 @@ use std::borrow::Cow;
53
43
/// use iced::widget::{button, column, text, Column};
54
44
///
55
45
/// pub fn main() -> iced::Result {
56
- /// iced::application ("A counter", update, view).run()
46
+ /// iced::program ("A counter", update, view).run()
57
47
/// }
58
48
///
59
49
/// #[derive(Debug, Clone)]
@@ -74,7 +64,7 @@ use std::borrow::Cow;
74
64
/// ]
75
65
/// }
76
66
/// ```
77
- pub fn application < State , Message > (
67
+ pub fn program < State , Message > (
78
68
title : impl Title < State > ,
79
69
update : impl Update < State , Message > ,
80
70
view : impl for < ' a > self :: View < ' a , State , Message > ,
@@ -139,22 +129,26 @@ where
139
129
. title ( title)
140
130
}
141
131
142
- /// A fully functioning and configured iced application.
132
+ /// The underlying definition and configuration of an iced [`Application`].
133
+ ///
134
+ /// You can use this API to create and run iced applications
135
+ /// step by step—without coupling your logic to a trait
136
+ /// or a specific type.
143
137
///
144
- /// It can be [`run`]!
138
+ /// This API is meant to be a more convenient—although less
139
+ /// powerful—alternative to the [`Application`] trait.
145
140
///
146
- /// Create one with the [`application `] helper.
141
+ /// You can create a [`Program`] with the [`program `] helper.
147
142
///
148
143
/// [`run`]: Program::run
149
- /// [`application`]: self::application()
150
144
#[ derive( Debug ) ]
151
145
pub struct Program < P : Definition > {
152
146
raw : P ,
153
147
settings : Settings ,
154
148
}
155
149
156
150
impl < P : Definition > Program < P > {
157
- /// Runs the [`Program`].
151
+ /// Runs the underlying [`Application`] of the [`Program`].
158
152
pub fn run ( self ) -> Result
159
153
where
160
154
Self : ' static ,
@@ -364,9 +358,7 @@ impl<P: Definition> Program<P> {
364
358
/// The internal definition of a [`Program`].
365
359
///
366
360
/// You should not need to implement this trait directly. Instead, use the
367
- /// helper functions available in the [`program`] module and the [`Program`] struct.
368
- ///
369
- /// [`program`]: crate::program
361
+ /// methods available in the [`Program`] struct.
370
362
#[ allow( missing_docs) ]
371
363
pub trait Definition : Sized {
372
364
/// The state of the program.
@@ -748,6 +740,8 @@ fn with_style<P: Definition>(
748
740
///
749
741
/// This trait is implemented both for `&static str` and
750
742
/// any closure `Fn(&State) -> String`.
743
+ ///
744
+ /// This trait allows the [`program`] builder to take any of them.
751
745
pub trait Title < State > {
752
746
/// Produces the title of the [`Program`].
753
747
fn title ( & self , state : & State ) -> String ;
@@ -770,10 +764,8 @@ where
770
764
771
765
/// The update logic of some [`Program`].
772
766
///
773
- /// This trait allows [`application`] to take any closure that
767
+ /// This trait allows the [`program`] builder to take any closure that
774
768
/// returns any `Into<Command<Message>>`.
775
- ///
776
- /// [`application`]: self::application()
777
769
pub trait Update < State , Message > {
778
770
/// Processes the message and updates the state of the [`Program`].
779
771
fn update (
@@ -799,10 +791,8 @@ where
799
791
800
792
/// The view logic of some [`Program`].
801
793
///
802
- /// This trait allows [`application`] to take any closure that
794
+ /// This trait allows the [`program`] builder to take any closure that
803
795
/// returns any `Into<Element<'_, Message>>`.
804
- ///
805
- /// [`application`]: self::application()
806
796
pub trait View < ' a , State , Message > {
807
797
/// Produces the widget of the [`Program`].
808
798
fn view ( & self , state : & ' a State ) -> impl Into < Element < ' a , Message > > ;
0 commit comments