From a25b1af45690bdd8e1cbb20ee3a5b1c4342de455 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 14 Jun 2024 01:47:39 +0200 Subject: Replace `Command` with a new `Task` API with chain support --- src/program.rs | 60 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'src/program.rs') diff --git a/src/program.rs b/src/program.rs index d4c2a266..ea6b0e8e 100644 --- a/src/program.rs +++ b/src/program.rs @@ -35,7 +35,7 @@ use crate::core::text; use crate::executor::{self, Executor}; use crate::graphics::compositor; use crate::window; -use crate::{Command, Element, Font, Result, Settings, Size, Subscription}; +use crate::{Element, Font, Result, Settings, Size, Subscription, Task}; pub use crate::application::{Appearance, DefaultStyle}; @@ -76,7 +76,7 @@ pub fn program( ) -> Program> where State: 'static, - Message: Send + std::fmt::Debug, + Message: Send + std::fmt::Debug + 'static, Theme: Default + DefaultStyle, Renderer: self::Renderer, { @@ -94,7 +94,7 @@ where impl Definition for Application where - Message: Send + std::fmt::Debug, + Message: Send + std::fmt::Debug + 'static, Theme: Default + DefaultStyle, Renderer: self::Renderer, Update: self::Update, @@ -106,15 +106,15 @@ where type Renderer = Renderer; type Executor = executor::Default; - fn load(&self) -> Command { - Command::none() + fn load(&self) -> Task { + Task::none() } fn update( &self, state: &mut Self::State, message: Self::Message, - ) -> Command { + ) -> Task { self.update.update(state, message).into() } @@ -197,7 +197,7 @@ impl Program

{ fn new( (program, initialize): Self::Flags, - ) -> (Self, Command) { + ) -> (Self, Task) { let state = initialize(); let command = program.load(); @@ -218,7 +218,7 @@ impl Program

{ fn update( &mut self, message: Self::Message, - ) -> Command { + ) -> Task { self.program.update(&mut self.state, message) } @@ -357,10 +357,10 @@ impl Program

{ } } - /// Runs the [`Command`] produced by the closure at startup. + /// Runs the [`Task`] produced by the closure at startup. pub fn load( self, - f: impl Fn() -> Command, + f: impl Fn() -> Task, ) -> Program< impl Definition, > { @@ -420,7 +420,7 @@ pub trait Definition: Sized { type State; /// The message of the program. - type Message: Send + std::fmt::Debug; + type Message: Send + std::fmt::Debug + 'static; /// The theme of the program. type Theme: Default + DefaultStyle; @@ -431,13 +431,13 @@ pub trait Definition: Sized { /// The executor of the program. type Executor: Executor; - fn load(&self) -> Command; + fn load(&self) -> Task; fn update( &self, state: &mut Self::State, message: Self::Message, - ) -> Command; + ) -> Task; fn view<'a>( &self, @@ -484,7 +484,7 @@ fn with_title( type Renderer = P::Renderer; type Executor = P::Executor; - fn load(&self) -> Command { + fn load(&self) -> Task { self.program.load() } @@ -496,7 +496,7 @@ fn with_title( &self, state: &mut Self::State, message: Self::Message, - ) -> Command { + ) -> Task { self.program.update(state, message) } @@ -532,7 +532,7 @@ fn with_title( fn with_load( program: P, - f: impl Fn() -> Command, + f: impl Fn() -> Task, ) -> impl Definition { struct WithLoad { program: P, @@ -541,7 +541,7 @@ fn with_load( impl Definition for WithLoad where - F: Fn() -> Command, + F: Fn() -> Task, { type State = P::State; type Message = P::Message; @@ -549,15 +549,15 @@ fn with_load( type Renderer = P::Renderer; type Executor = executor::Default; - fn load(&self) -> Command { - Command::batch([self.program.load(), (self.load)()]) + fn load(&self) -> Task { + Task::batch([self.program.load(), (self.load)()]) } fn update( &self, state: &mut Self::State, message: Self::Message, - ) -> Command { + ) -> Task { self.program.update(state, message) } @@ -621,7 +621,7 @@ fn with_subscription( (self.subscription)(state) } - fn load(&self) -> Command { + fn load(&self) -> Task { self.program.load() } @@ -629,7 +629,7 @@ fn with_subscription( &self, state: &mut Self::State, message: Self::Message, - ) -> Command { + ) -> Task { self.program.update(state, message) } @@ -686,7 +686,7 @@ fn with_theme( (self.theme)(state) } - fn load(&self) -> Command { + fn load(&self) -> Task { self.program.load() } @@ -698,7 +698,7 @@ fn with_theme( &self, state: &mut Self::State, message: Self::Message, - ) -> Command { + ) -> Task { self.program.update(state, message) } @@ -755,7 +755,7 @@ fn with_style( (self.style)(state, theme) } - fn load(&self) -> Command { + fn load(&self) -> Task { self.program.load() } @@ -767,7 +767,7 @@ fn with_style( &self, state: &mut Self::State, message: Self::Message, - ) -> Command { + ) -> Task { self.program.update(state, message) } @@ -822,26 +822,26 @@ where /// The update logic of some [`Program`]. /// /// This trait allows the [`program`] builder to take any closure that -/// returns any `Into>`. +/// returns any `Into>`. pub trait Update { /// Processes the message and updates the state of the [`Program`]. fn update( &self, state: &mut State, message: Message, - ) -> impl Into>; + ) -> impl Into>; } impl Update for T where T: Fn(&mut State, Message) -> C, - C: Into>, + C: Into>, { fn update( &self, state: &mut State, message: Message, - ) -> impl Into> { + ) -> impl Into> { self(state, message) } } -- cgit