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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue