From fd66a4c0d9cb049dd534c989300582ae9da694f6 Mon Sep 17 00:00:00 2001 From: Philipp Mildenberger Date: Thu, 25 Jan 2024 18:10:50 +0100 Subject: [PATCH] Add macro beatifications of #164 and adjust the invocations of it --- crates/xilem_core/src/view/mod.rs | 10 +++++----- crates/xilem_web/src/view.rs | 2 +- src/view/view.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/xilem_core/src/view/mod.rs b/crates/xilem_core/src/view/mod.rs index 645ad2bd1..c6703bbe5 100644 --- a/crates/xilem_core/src/view/mod.rs +++ b/crates/xilem_core/src/view/mod.rs @@ -16,11 +16,11 @@ mod memoize; /// methods, and be responsible for managing element creation & deletion. /// - `$changeflags` - The type that reports down/up the tree. Can be used to avoid /// doing work when we can prove nothing needs doing. -/// - `$super_bounds` - (optional) parent traits to this trait (e.g. `+ Send`). -/// - `$state_bounds` - (optional) trait bounds for the associated type `State` (e.g. `: Send`). +/// - `$super_bounds` - (optional) parent traits to this trait (e.g. `Send + Sync`). +/// - `$state_bounds` - (optional) trait bounds for the associated type `State` (e.g. `Send`). #[macro_export] macro_rules! generate_view_trait { - ($viewtrait:ident, $viewmarker:ident, $bound:ident, $cx:ty, $changeflags:ty; ($($super_bounds:tt)*), ($($state_bounds:tt)*)) => { + ($viewtrait:ident, $viewmarker:ident, $bound:ident, $cx:ty, $changeflags:ty; $(($($super_bounds:tt)*))? $(,($($state_bounds:tt)*))?) => { /// A view object representing a node in the UI. /// /// This is a central trait for representing UI. An app will generate a tree of @@ -38,9 +38,9 @@ macro_rules! generate_view_trait { /// and also a type for actions which are passed up the tree in message /// propagation. During message handling, mutable access to the app state is /// given to view nodes, which in turn can expose it to callbacks. - pub trait $viewtrait: $viewmarker $( $super_bounds )* { + pub trait $viewtrait: $viewmarker + $($( $super_bounds )*)? { /// Associated state for the view. - type State $( $state_bounds )*; + type State: $($( $state_bounds )*)?; /// The associated element for the view. type Element: $bound; diff --git a/crates/xilem_web/src/view.rs b/crates/xilem_web/src/view.rs index edaf2e0a1..430ae9c56 100644 --- a/crates/xilem_web/src/view.rs +++ b/crates/xilem_web/src/view.rs @@ -84,7 +84,7 @@ impl Pod { } } -xilem_core::generate_view_trait! {View, ViewMarker, DomNode, Cx, ChangeFlags;(),()} +xilem_core::generate_view_trait! {View, ViewMarker, DomNode, Cx, ChangeFlags;} xilem_core::generate_viewsequence_trait! {ViewSequence, View, ViewMarker, DomNode, Cx, ChangeFlags, Pod;} xilem_core::generate_anyview_trait! {AnyView, View, ViewMarker, Cx, ChangeFlags, AnyNode, BoxedView;} xilem_core::generate_memoize_view! {Memoize, MemoizeState, View, ViewMarker, Cx, ChangeFlags, static_view, memoize;} diff --git a/src/view/view.rs b/src/view/view.rs index 30ec59a01..ed0181f40 100644 --- a/src/view/view.rs +++ b/src/view/view.rs @@ -23,7 +23,7 @@ use xilem_core::{Id, IdPath}; use crate::widget::{AnyWidget, ChangeFlags, Pod, Widget}; -xilem_core::generate_view_trait! {View, ViewMarker, Widget, Cx, ChangeFlags; (+ Send), (: Send)} +xilem_core::generate_view_trait! {View, ViewMarker, Widget, Cx, ChangeFlags; (Send), (Send)} xilem_core::generate_viewsequence_trait! {ViewSequence, View, ViewMarker, Widget, Cx, ChangeFlags, Pod; : Send} xilem_core::generate_anyview_trait! {AnyView, View, ViewMarker, Cx, ChangeFlags, AnyWidget, BoxedView; + Send} xilem_core::generate_memoize_view! {Memoize, MemoizeState, View, ViewMarker, Cx, ChangeFlags, s, memoize; + Send}