Add Fn suffix to application and daemon traits
This commit is contained in:
parent
323b17d458
commit
9518573fce
4 changed files with 44 additions and 44 deletions
|
|
@ -75,9 +75,9 @@ pub use timed::timed;
|
|||
/// }
|
||||
/// ```
|
||||
pub fn application<State, Message, Theme, Renderer>(
|
||||
boot: impl Boot<State, Message>,
|
||||
update: impl Update<State, Message>,
|
||||
view: impl for<'a> View<'a, State, Message, Theme, Renderer>,
|
||||
boot: impl BootFn<State, Message>,
|
||||
update: impl UpdateFn<State, Message>,
|
||||
view: impl for<'a> ViewFn<'a, State, Message, Theme, Renderer>,
|
||||
) -> Application<impl Program<State = State, Message = Message, Theme = Theme>>
|
||||
where
|
||||
State: 'static,
|
||||
|
|
@ -103,9 +103,9 @@ where
|
|||
Message: program::Message + 'static,
|
||||
Theme: theme::Base,
|
||||
Renderer: program::Renderer,
|
||||
Boot: self::Boot<State, Message>,
|
||||
Update: self::Update<State, Message>,
|
||||
View: for<'a> self::View<'a, State, Message, Theme, Renderer>,
|
||||
Boot: self::BootFn<State, Message>,
|
||||
Update: self::UpdateFn<State, Message>,
|
||||
View: for<'a> self::ViewFn<'a, State, Message, Theme, Renderer>,
|
||||
{
|
||||
type State = State;
|
||||
type Message = Message;
|
||||
|
|
@ -320,10 +320,10 @@ impl<P: Program> Application<P> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Sets the [`Title`] of the [`Application`].
|
||||
/// Sets the title of the [`Application`].
|
||||
pub fn title(
|
||||
self,
|
||||
title: impl Title<P::State>,
|
||||
title: impl TitleFn<P::State>,
|
||||
) -> Application<
|
||||
impl Program<State = P::State, Message = P::Message, Theme = P::Theme>,
|
||||
> {
|
||||
|
|
@ -425,12 +425,12 @@ impl<P: Program> Application<P> {
|
|||
/// In practice, this means that [`application`] can both take
|
||||
/// simple functions like `State::default` and more advanced ones
|
||||
/// that return a [`Task`].
|
||||
pub trait Boot<State, Message> {
|
||||
pub trait BootFn<State, Message> {
|
||||
/// Initializes the [`Application`] state.
|
||||
fn boot(&self) -> (State, Task<Message>);
|
||||
}
|
||||
|
||||
impl<T, C, State, Message> Boot<State, Message> for T
|
||||
impl<T, C, State, Message> BootFn<State, Message> for T
|
||||
where
|
||||
T: Fn() -> C,
|
||||
C: IntoBoot<State, Message>,
|
||||
|
|
@ -464,18 +464,18 @@ impl<State, Message> IntoBoot<State, Message> for (State, Task<Message>) {
|
|||
/// any closure `Fn(&State) -> String`.
|
||||
///
|
||||
/// This trait allows the [`application`] builder to take any of them.
|
||||
pub trait Title<State> {
|
||||
pub trait TitleFn<State> {
|
||||
/// Produces the title of the [`Application`].
|
||||
fn title(&self, state: &State) -> String;
|
||||
}
|
||||
|
||||
impl<State> Title<State> for &'static str {
|
||||
impl<State> TitleFn<State> for &'static str {
|
||||
fn title(&self, _state: &State) -> String {
|
||||
self.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, State> Title<State> for T
|
||||
impl<T, State> TitleFn<State> for T
|
||||
where
|
||||
T: Fn(&State) -> String,
|
||||
{
|
||||
|
|
@ -488,18 +488,18 @@ where
|
|||
///
|
||||
/// This trait allows the [`application`] builder to take any closure that
|
||||
/// returns any `Into<Task<Message>>`.
|
||||
pub trait Update<State, Message> {
|
||||
pub trait UpdateFn<State, Message> {
|
||||
/// Processes the message and updates the state of the [`Application`].
|
||||
fn update(&self, state: &mut State, message: Message) -> Task<Message>;
|
||||
}
|
||||
|
||||
impl<State, Message> Update<State, Message> for () {
|
||||
impl<State, Message> UpdateFn<State, Message> for () {
|
||||
fn update(&self, _state: &mut State, _message: Message) -> Task<Message> {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, State, Message, C> Update<State, Message> for T
|
||||
impl<T, State, Message, C> UpdateFn<State, Message> for T
|
||||
where
|
||||
T: Fn(&mut State, Message) -> C,
|
||||
C: Into<Task<Message>>,
|
||||
|
|
@ -513,13 +513,13 @@ where
|
|||
///
|
||||
/// This trait allows the [`application`] builder to take any closure that
|
||||
/// returns any `Into<Element<'_, Message>>`.
|
||||
pub trait View<'a, State, Message, Theme, Renderer> {
|
||||
pub trait ViewFn<'a, State, Message, Theme, Renderer> {
|
||||
/// Produces the widget of the [`Application`].
|
||||
fn view(&self, state: &'a State) -> Element<'a, Message, Theme, Renderer>;
|
||||
}
|
||||
|
||||
impl<'a, T, State, Message, Theme, Renderer, Widget>
|
||||
View<'a, State, Message, Theme, Renderer> for T
|
||||
ViewFn<'a, State, Message, Theme, Renderer> for T
|
||||
where
|
||||
T: Fn(&'a State) -> Widget,
|
||||
State: 'static,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//! An [`Application`] that receives an [`Instant`] in update logic.
|
||||
use crate::application::{Application, Boot, View};
|
||||
use crate::application::{Application, BootFn, ViewFn};
|
||||
use crate::program;
|
||||
use crate::theme;
|
||||
use crate::time::Instant;
|
||||
|
|
@ -20,10 +20,10 @@ use iced_debug as debug;
|
|||
///
|
||||
/// [`comet`]: https://github.com/iced-rs/comet
|
||||
pub fn timed<State, Message, Theme, Renderer>(
|
||||
boot: impl Boot<State, Message>,
|
||||
update: impl Update<State, Message>,
|
||||
boot: impl BootFn<State, Message>,
|
||||
update: impl UpdateFn<State, Message>,
|
||||
subscription: impl Fn(&State) -> Subscription<Message>,
|
||||
view: impl for<'a> View<'a, State, Message, Theme, Renderer>,
|
||||
view: impl for<'a> ViewFn<'a, State, Message, Theme, Renderer>,
|
||||
) -> Application<
|
||||
impl Program<State = State, Message = (Message, Instant), Theme = Theme>,
|
||||
>
|
||||
|
|
@ -71,10 +71,10 @@ where
|
|||
Message: program::Message + 'static,
|
||||
Theme: theme::Base + 'static,
|
||||
Renderer: program::Renderer + 'static,
|
||||
Boot: self::Boot<State, Message>,
|
||||
Update: self::Update<State, Message>,
|
||||
Boot: self::BootFn<State, Message>,
|
||||
Update: self::UpdateFn<State, Message>,
|
||||
Subscription: Fn(&State) -> self::Subscription<Message>,
|
||||
View: for<'a> self::View<'a, State, Message, Theme, Renderer>,
|
||||
View: for<'a> self::ViewFn<'a, State, Message, Theme, Renderer>,
|
||||
{
|
||||
type State = State;
|
||||
type Message = (Message, Instant);
|
||||
|
|
@ -148,9 +148,9 @@ where
|
|||
|
||||
/// The update logic of some timed [`Application`].
|
||||
///
|
||||
/// This is like [`application::Update`](super::Update),
|
||||
/// This is like [`application::UpdateFn`](super::UpdateFn),
|
||||
/// but it also takes an [`Instant`].
|
||||
pub trait Update<State, Message> {
|
||||
pub trait UpdateFn<State, Message> {
|
||||
/// Processes the message and updates the state of the [`Application`].
|
||||
fn update(
|
||||
&self,
|
||||
|
|
@ -160,7 +160,7 @@ pub trait Update<State, Message> {
|
|||
) -> impl Into<Task<Message>>;
|
||||
}
|
||||
|
||||
impl<State, Message> Update<State, Message> for () {
|
||||
impl<State, Message> UpdateFn<State, Message> for () {
|
||||
fn update(
|
||||
&self,
|
||||
_state: &mut State,
|
||||
|
|
@ -170,7 +170,7 @@ impl<State, Message> Update<State, Message> for () {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, State, Message, C> Update<State, Message> for T
|
||||
impl<T, State, Message, C> UpdateFn<State, Message> for T
|
||||
where
|
||||
T: Fn(&mut State, Message, Instant) -> C,
|
||||
C: Into<Task<Message>>,
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ use std::borrow::Cow;
|
|||
///
|
||||
/// [`exit`]: crate::exit
|
||||
pub fn daemon<State, Message, Theme, Renderer>(
|
||||
boot: impl application::Boot<State, Message>,
|
||||
update: impl application::Update<State, Message>,
|
||||
view: impl for<'a> View<'a, State, Message, Theme, Renderer>,
|
||||
boot: impl application::BootFn<State, Message>,
|
||||
update: impl application::UpdateFn<State, Message>,
|
||||
view: impl for<'a> ViewFn<'a, State, Message, Theme, Renderer>,
|
||||
) -> Daemon<impl Program<State = State, Message = Message, Theme = Theme>>
|
||||
where
|
||||
State: 'static,
|
||||
|
|
@ -51,9 +51,9 @@ where
|
|||
Message: program::Message + 'static,
|
||||
Theme: theme::Base,
|
||||
Renderer: program::Renderer,
|
||||
Boot: application::Boot<State, Message>,
|
||||
Update: application::Update<State, Message>,
|
||||
View: for<'a> self::View<'a, State, Message, Theme, Renderer>,
|
||||
Boot: application::BootFn<State, Message>,
|
||||
Update: application::UpdateFn<State, Message>,
|
||||
View: for<'a> self::ViewFn<'a, State, Message, Theme, Renderer>,
|
||||
{
|
||||
type State = State;
|
||||
type Message = Message;
|
||||
|
|
@ -171,10 +171,10 @@ impl<P: Program> Daemon<P> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Sets the [`Title`] of the [`Daemon`].
|
||||
/// Sets the title of the [`Daemon`].
|
||||
pub fn title(
|
||||
self,
|
||||
title: impl Title<P::State>,
|
||||
title: impl TitleFn<P::State>,
|
||||
) -> Daemon<
|
||||
impl Program<State = P::State, Message = P::Message, Theme = P::Theme>,
|
||||
> {
|
||||
|
|
@ -268,18 +268,18 @@ impl<P: Program> Daemon<P> {
|
|||
/// any closure `Fn(&State, window::Id) -> String`.
|
||||
///
|
||||
/// This trait allows the [`daemon`] builder to take any of them.
|
||||
pub trait Title<State> {
|
||||
pub trait TitleFn<State> {
|
||||
/// Produces the title of the [`Daemon`].
|
||||
fn title(&self, state: &State, window: window::Id) -> String;
|
||||
}
|
||||
|
||||
impl<State> Title<State> for &'static str {
|
||||
impl<State> TitleFn<State> for &'static str {
|
||||
fn title(&self, _state: &State, _window: window::Id) -> String {
|
||||
self.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, State> Title<State> for T
|
||||
impl<T, State> TitleFn<State> for T
|
||||
where
|
||||
T: Fn(&State, window::Id) -> String,
|
||||
{
|
||||
|
|
@ -292,7 +292,7 @@ where
|
|||
///
|
||||
/// This trait allows the [`daemon`] builder to take any closure that
|
||||
/// returns any `Into<Element<'_, Message>>`.
|
||||
pub trait View<'a, State, Message, Theme, Renderer> {
|
||||
pub trait ViewFn<'a, State, Message, Theme, Renderer> {
|
||||
/// Produces the widget of the [`Daemon`].
|
||||
fn view(
|
||||
&self,
|
||||
|
|
@ -302,7 +302,7 @@ pub trait View<'a, State, Message, Theme, Renderer> {
|
|||
}
|
||||
|
||||
impl<'a, T, State, Message, Theme, Renderer, Widget>
|
||||
View<'a, State, Message, Theme, Renderer> for T
|
||||
ViewFn<'a, State, Message, Theme, Renderer> for T
|
||||
where
|
||||
T: Fn(&'a State, window::Id) -> Widget,
|
||||
State: 'static,
|
||||
|
|
|
|||
|
|
@ -691,8 +691,8 @@ pub type Result = std::result::Result<(), Error>;
|
|||
/// }
|
||||
/// ```
|
||||
pub fn run<State, Message, Theme, Renderer>(
|
||||
update: impl application::Update<State, Message> + 'static,
|
||||
view: impl for<'a> application::View<'a, State, Message, Theme, Renderer>
|
||||
update: impl application::UpdateFn<State, Message> + 'static,
|
||||
view: impl for<'a> application::ViewFn<'a, State, Message, Theme, Renderer>
|
||||
+ 'static,
|
||||
) -> Result
|
||||
where
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue