From c52fd089f102be4e2ac07952106e2b6924e72e68 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 9 Mar 2022 18:27:22 +0700 Subject: Use associated type for `Message` in a `canvas::Program` --- graphics/src/widget/canvas/program.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'graphics/src/widget/canvas/program.rs') diff --git a/graphics/src/widget/canvas/program.rs b/graphics/src/widget/canvas/program.rs index 85a2f67b..f8b9ff2b 100644 --- a/graphics/src/widget/canvas/program.rs +++ b/graphics/src/widget/canvas/program.rs @@ -8,7 +8,10 @@ use iced_native::{mouse, Rectangle}; /// application. /// /// [`Canvas`]: crate::widget::Canvas -pub trait Program { +pub trait Program { + /// The [`Message`] produced by the [`Program`]. + type Message; + /// Updates the state of the [`Program`]. /// /// When a [`Program`] is used in a [`Canvas`], the runtime will call this @@ -25,7 +28,7 @@ pub trait Program { _event: Event, _bounds: Rectangle, _cursor: Cursor, - ) -> (event::Status, Option) { + ) -> (event::Status, Option) { (event::Status::Ignored, None) } @@ -53,16 +56,18 @@ pub trait Program { } } -impl Program for &mut T +impl Program for &mut T where - T: Program, + T: Program, { + type Message = T::Message; + fn update( &mut self, event: Event, bounds: Rectangle, cursor: Cursor, - ) -> (event::Status, Option) { + ) -> (event::Status, Option) { T::update(self, event, bounds, cursor) } -- cgit