Remove some indirection in application traits

Skill issue, though.
This commit is contained in:
Héctor Ramón Jiménez 2025-05-13 22:29:20 +02:00
parent 3a3a02beef
commit 8c87f67d6d
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 13 additions and 31 deletions

View file

@ -75,7 +75,7 @@ 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> self::View<'a, State, Message, Theme, Renderer>,
view: impl for<'a> View<'a, State, Message, Theme, Renderer>,
) -> Application<impl Program<State = State, Message = Message, Theme = Theme>>
where
State: 'static,
@ -482,19 +482,12 @@ where
/// returns any `Into<Task<Message>>`.
pub trait Update<State, Message> {
/// Processes the message and updates the state of the [`Application`].
fn update(
&self,
state: &mut State,
message: Message,
) -> impl Into<Task<Message>>;
fn update(&self, state: &mut State, message: Message) -> Task<Message>;
}
impl<State, Message> Update<State, Message> for () {
fn update(
&self,
_state: &mut State,
_message: Message,
) -> impl Into<Task<Message>> {
fn update(&self, _state: &mut State, _message: Message) -> Task<Message> {
Task::none()
}
}
@ -503,12 +496,8 @@ where
T: Fn(&mut State, Message) -> C,
C: Into<Task<Message>>,
{
fn update(
&self,
state: &mut State,
message: Message,
) -> impl Into<Task<Message>> {
self(state, message)
fn update(&self, state: &mut State, message: Message) -> Task<Message> {
self(state, message).into()
}
}
@ -518,10 +507,7 @@ where
/// returns any `Into<Element<'_, Message>>`.
pub trait View<'a, State, Message, Theme, Renderer> {
/// Produces the widget of the [`Application`].
fn view(
&self,
state: &'a State,
) -> impl Into<Element<'a, Message, Theme, Renderer>>;
fn view(&self, state: &'a State) -> Element<'a, Message, Theme, Renderer>;
}
impl<'a, T, State, Message, Theme, Renderer, Widget>
@ -531,10 +517,7 @@ where
State: 'static,
Widget: Into<Element<'a, Message, Theme, Renderer>>,
{
fn view(
&self,
state: &'a State,
) -> impl Into<Element<'a, Message, Theme, Renderer>> {
self(state)
fn view(&self, state: &'a State) -> Element<'a, Message, Theme, Renderer> {
self(state).into()
}
}

View file

@ -110,7 +110,6 @@ where
) -> Element<'a, Self::Message, Self::Theme, Self::Renderer> {
self.view
.view(state)
.into()
.map(|message| (message, Instant::now()))
}

View file

@ -21,7 +21,7 @@ use std::borrow::Cow;
pub fn daemon<State, Message, Theme, Renderer>(
boot: impl application::Boot<State, Message>,
update: impl application::Update<State, Message>,
view: impl for<'a> self::View<'a, State, Message, Theme, Renderer>,
view: impl for<'a> View<'a, State, Message, Theme, Renderer>,
) -> Daemon<impl Program<State = State, Message = Message, Theme = Theme>>
where
State: 'static,
@ -286,7 +286,7 @@ pub trait View<'a, State, Message, Theme, Renderer> {
&self,
state: &'a State,
window: window::Id,
) -> impl Into<Element<'a, Message, Theme, Renderer>>;
) -> Element<'a, Message, Theme, Renderer>;
}
impl<'a, T, State, Message, Theme, Renderer, Widget>
@ -300,7 +300,7 @@ where
&self,
state: &'a State,
window: window::Id,
) -> impl Into<Element<'a, Message, Theme, Renderer>> {
self(state, window)
) -> Element<'a, Message, Theme, Renderer> {
self(state, window).into()
}
}