Skip to content

Commit

Permalink
Add macro beatifications of #164 and adjust the invocations of it
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp-M committed Feb 15, 2024
1 parent 1c4980f commit fd66a4c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions crates/xilem_core/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<T, A = ()>: $viewmarker $( $super_bounds )* {
pub trait $viewtrait<T, A = ()>: $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;
Expand Down
2 changes: 1 addition & 1 deletion crates/xilem_web/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;}
Expand Down
2 changes: 1 addition & 1 deletion src/view/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit fd66a4c

Please sign in to comment.