summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-17 14:16:38 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-17 14:19:12 +0100
commit54f44754eb216d4b2c08cd2a7c3582f1dc295205 (patch)
tree9f4a999ad92c62a1cf4df4559ff320fda83577c1 /src
parent7e1ef7d150aa3d4d05942eea2706348f20d61d64 (diff)
downloadiced-54f44754eb216d4b2c08cd2a7c3582f1dc295205.tar.gz
iced-54f44754eb216d4b2c08cd2a7c3582f1dc295205.tar.bz2
iced-54f44754eb216d4b2c08cd2a7c3582f1dc295205.zip
Move `Program` to `application` module
Diffstat (limited to 'src')
-rw-r--r--src/application.rs5
-rw-r--r--src/application/program.rs (renamed from src/program.rs)44
-rw-r--r--src/lib.rs15
3 files changed, 27 insertions, 37 deletions
diff --git a/src/application.rs b/src/application.rs
index 48fc672a..ba60db67 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -1,7 +1,10 @@
//! Build interactive cross-platform applications.
-use crate::{Command, Element, Executor, Settings, Subscription};
+mod program;
+
+pub use program::{program, Definition, Program, Title, Update, View};
use crate::shell::application;
+use crate::{Command, Element, Executor, Settings, Subscription};
pub use application::{default, Appearance, DefaultStyle};
diff --git a/src/program.rs b/src/application/program.rs
index b379dccf..24e00efe 100644
--- a/src/program.rs
+++ b/src/application/program.rs
@@ -1,13 +1,3 @@
-//! Create iced applications out of simple functions.
-//!
-//! You can use this API to create and run iced applications
-//! step by step—without coupling your logic to a trait
-//! or a specific type.
-//!
-//! This API is meant to be a more convenient—although less
-//! powerful—alternative to the [`Application`] traits.
-//!
-//! [`Sandbox`]: crate::Sandbox
//!
//! # Example
//! ```no_run
@@ -15,7 +5,7 @@
//! use iced::Theme;
//!
//! pub fn main() -> iced::Result {
-//! iced::application("A counter", update, view)
+//! iced::program("A counter", update, view)
//! .theme(|_| Theme::Dark)
//! .centered()
//! .run()
@@ -53,7 +43,7 @@ use std::borrow::Cow;
/// use iced::widget::{button, column, text, Column};
///
/// pub fn main() -> iced::Result {
-/// iced::application("A counter", update, view).run()
+/// iced::program("A counter", update, view).run()
/// }
///
/// #[derive(Debug, Clone)]
@@ -74,7 +64,7 @@ use std::borrow::Cow;
/// ]
/// }
/// ```
-pub fn application<State, Message>(
+pub fn program<State, Message>(
title: impl Title<State>,
update: impl Update<State, Message>,
view: impl for<'a> self::View<'a, State, Message>,
@@ -139,14 +129,18 @@ where
.title(title)
}
-/// A fully functioning and configured iced application.
+/// The underlying definition and configuration of an iced [`Application`].
+///
+/// You can use this API to create and run iced applications
+/// step by step—without coupling your logic to a trait
+/// or a specific type.
///
-/// It can be [`run`]!
+/// This API is meant to be a more convenient—although less
+/// powerful—alternative to the [`Application`] trait.
///
-/// Create one with the [`application`] helper.
+/// You can create a [`Program`] with the [`program`] helper.
///
/// [`run`]: Program::run
-/// [`application`]: self::application()
#[derive(Debug)]
pub struct Program<P: Definition> {
raw: P,
@@ -154,7 +148,7 @@ pub struct Program<P: Definition> {
}
impl<P: Definition> Program<P> {
- /// Runs the [`Program`].
+ /// Runs the underlying [`Application`] of the [`Program`].
pub fn run(self) -> Result
where
Self: 'static,
@@ -364,9 +358,7 @@ impl<P: Definition> Program<P> {
/// The internal definition of a [`Program`].
///
/// You should not need to implement this trait directly. Instead, use the
-/// helper functions available in the [`program`] module and the [`Program`] struct.
-///
-/// [`program`]: crate::program
+/// methods available in the [`Program`] struct.
#[allow(missing_docs)]
pub trait Definition: Sized {
/// The state of the program.
@@ -748,6 +740,8 @@ fn with_style<P: Definition>(
///
/// This trait is implemented both for `&static str` and
/// any closure `Fn(&State) -> String`.
+///
+/// This trait allows the [`program`] builder to take any of them.
pub trait Title<State> {
/// Produces the title of the [`Program`].
fn title(&self, state: &State) -> String;
@@ -770,10 +764,8 @@ where
/// The update logic of some [`Program`].
///
-/// This trait allows [`application`] to take any closure that
+/// This trait allows the [`program`] builder to take any closure that
/// returns any `Into<Command<Message>>`.
-///
-/// [`application`]: self::application()
pub trait Update<State, Message> {
/// Processes the message and updates the state of the [`Program`].
fn update(
@@ -799,10 +791,8 @@ where
/// The view logic of some [`Program`].
///
-/// This trait allows [`application`] to take any closure that
+/// This trait allows the [`program`] builder to take any closure that
/// returns any `Into<Element<'_, Message>>`.
-///
-/// [`application`]: self::application()
pub trait View<'a, State, Message> {
/// Produces the widget of the [`Program`].
fn view(&self, state: &'a State) -> impl Into<Element<'a, Message>>;
diff --git a/src/lib.rs b/src/lib.rs
index c2177484..def020e0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -157,12 +157,11 @@
//! 1. Draw the resulting user interface.
//!
//! # Usage
-//! You can either use the [`application`] builder or implement the [`Application`]
+//! You can either use the [`program`] builder or implement the [`Application`]
//! trait directly.
//!
//! [Elm]: https://elm-lang.org/
//! [The Elm Architecture]: https://guide.elm-lang.org/architecture/
-//! [`application`]: application()
#![doc(
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
)]
@@ -189,7 +188,6 @@ pub use iced_highlighter as highlighter;
mod error;
pub mod application;
-pub mod program;
pub mod settings;
pub mod time;
pub mod window;
@@ -323,7 +321,6 @@ pub use error::Error;
pub use event::Event;
pub use executor::Executor;
pub use font::Font;
-pub use program::Program;
pub use renderer::Renderer;
pub use settings::Settings;
pub use subscription::Subscription;
@@ -375,16 +372,16 @@ pub type Result = std::result::Result<(), Error>;
/// }
/// ```
pub fn run<State, Message>(
- title: impl program::Title<State> + 'static,
- update: impl program::Update<State, Message> + 'static,
- view: impl for<'a> program::View<'a, State, Message> + 'static,
+ title: impl application::Title<State> + 'static,
+ update: impl application::Update<State, Message> + 'static,
+ view: impl for<'a> application::View<'a, State, Message> + 'static,
) -> Result
where
State: Default + 'static,
Message: std::fmt::Debug + Send + 'static,
{
- application(title, update, view).run()
+ program(title, update, view).run()
}
#[doc(inline)]
-pub use program::application;
+pub use application::program;