From bc8e9fecd2ca2ea562abf5a34a6e0546dee6b361 Mon Sep 17 00:00:00 2001 From: Olivier FAURE Date: Wed, 5 Mar 2025 13:15:47 +0000 Subject: [PATCH] Switch to Edition 2024 (#880) I've ignored most of the changes and the projects still compile and test fine. Changes I did commit: Add `+ use<>` after functions. Remove `ref mut` from some patterns. Bump MSRV. Apply new rustfmt format. --- .github/workflows/ci.yml | 2 +- Cargo.toml | 6 +- README.md | 2 +- masonry/README.md | 2 +- masonry/examples/calc_masonry.rs | 4 +- masonry/examples/custom_widget.rs | 4 +- masonry/src/app/mod.rs | 2 +- masonry/src/app/render_root.rs | 10 +-- masonry/src/app/tracing_backend.rs | 2 +- masonry/src/core/mod.rs | 2 +- masonry/src/core/text.rs | 2 +- masonry/src/core/widget.rs | 4 +- masonry/src/core/widget_ref.rs | 2 +- masonry/src/passes/event.rs | 2 +- masonry/src/passes/layout.rs | 4 +- masonry/src/passes/paint.rs | 2 +- masonry/src/testing/harness.rs | 6 +- masonry/src/testing/helper_widgets.rs | 14 ++-- masonry/src/testing/screenshots.rs | 2 +- masonry/src/util.rs | 8 +-- masonry/src/widgets/align.rs | 4 +- masonry/src/widgets/button.rs | 8 +-- masonry/src/widgets/checkbox.rs | 10 +-- masonry/src/widgets/flex.rs | 8 ++- masonry/src/widgets/grid.rs | 4 +- masonry/src/widgets/image.rs | 4 +- masonry/src/widgets/label.rs | 10 +-- masonry/src/widgets/portal.rs | 8 +-- masonry/src/widgets/progress_bar.rs | 8 +-- masonry/src/widgets/prose.rs | 8 +-- masonry/src/widgets/root_widget.rs | 6 +- masonry/src/widgets/scroll_bar.rs | 6 +- masonry/src/widgets/sized_box.rs | 18 ++--- masonry/src/widgets/spinner.rs | 4 +- masonry/src/widgets/split.rs | 4 +- masonry/src/widgets/tests/layout.rs | 2 +- masonry/src/widgets/tests/lifecycle_basic.rs | 2 +- .../src/widgets/tests/lifecycle_disable.rs | 11 ++- masonry/src/widgets/tests/lifecycle_focus.rs | 2 +- masonry/src/widgets/tests/status_change.rs | 8 +-- masonry/src/widgets/tests/widget_tree.rs | 2 +- masonry/src/widgets/text_area.rs | 12 ++-- masonry/src/widgets/textbox.rs | 6 +- masonry/src/widgets/variable_label.rs | 6 +- xilem/README.md | 4 +- xilem/examples/calc.rs | 12 ++-- xilem/examples/components.rs | 6 +- xilem/examples/elm.rs | 6 +- xilem/examples/emoji_picker.rs | 10 +-- xilem/examples/external_event_loop.rs | 4 +- xilem/examples/flex.rs | 4 +- xilem/examples/http_cats.rs | 14 ++-- xilem/examples/mason.rs | 12 ++-- xilem/examples/memoization.rs | 4 +- xilem/examples/state_machine.rs | 4 +- xilem/examples/stopwatch.rs | 12 ++-- xilem/examples/to_do_mvc.rs | 6 +- xilem/examples/transforms.rs | 4 +- xilem/examples/variable_clock.rs | 14 ++-- xilem/examples/widgets.rs | 8 +-- xilem/src/any_view.rs | 4 +- xilem/src/driver.rs | 4 +- xilem/src/lib.rs | 10 +-- xilem/src/one_of.rs | 44 ++++++------ xilem/src/view/flex.rs | 2 +- xilem/src/view/image.rs | 4 +- xilem/src/view/label.rs | 4 +- xilem/src/view/progress_bar.rs | 4 +- xilem/src/view/prose.rs | 4 +- xilem/src/view/spinner.rs | 4 +- xilem/src/view/task.rs | 2 +- xilem/src/view/variable_label.rs | 8 ++- xilem/src/view/worker.rs | 2 +- xilem_core/README.md | 2 +- xilem_core/examples/filesystem.rs | 4 +- xilem_core/examples/user_interface.rs | 2 +- xilem_core/src/any_view.rs | 8 +-- xilem_core/src/docs.rs | 4 +- xilem_core/src/lib.rs | 4 +- xilem_core/src/views/mod.rs | 12 ++-- xilem_core/src/views/one_of.rs | 72 +++++++++---------- xilem_web/README.md | 4 +- xilem_web/src/concurrent/mod.rs | 6 +- xilem_web/src/concurrent/task.rs | 2 +- xilem_web/src/context.rs | 2 +- xilem_web/src/elements.rs | 2 +- xilem_web/src/events.rs | 4 +- xilem_web/src/interfaces.rs | 10 +-- xilem_web/src/lib.rs | 4 +- xilem_web/src/modifiers/class.rs | 2 +- xilem_web/src/modifiers/overwrite.rs | 8 +-- xilem_web/src/modifiers/style.rs | 2 +- xilem_web/src/one_of.rs | 2 +- xilem_web/src/pointer.rs | 2 +- xilem_web/src/props/element.rs | 2 +- xilem_web/src/props/html_input_element.rs | 16 ++--- xilem_web/src/svg/common_attrs.rs | 10 +-- xilem_web/src/svg/kurbo_shape.rs | 2 +- xilem_web/src/svg/mod.rs | 2 +- xilem_web/web_examples/counter/src/main.rs | 6 +- .../counter_custom_element/src/main.rs | 4 +- xilem_web/web_examples/elm/src/main.rs | 4 +- xilem_web/web_examples/fetch/src/main.rs | 8 +-- xilem_web/web_examples/mathml_svg/src/main.rs | 2 +- .../web_examples/raw_dom_access/src/main.rs | 4 +- .../web_examples/spawn_tasks/src/main.rs | 8 +-- xilem_web/web_examples/svgdraw/src/main.rs | 6 +- xilem_web/web_examples/svgtoy/src/main.rs | 6 +- xilem_web/web_examples/todomvc/src/main.rs | 12 ++-- 109 files changed, 354 insertions(+), 359 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c7110e4..cf4daab5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ env: # If the compilation fails, then the version specified here needs to be bumped up to reality. # Be sure to also update the rust-version property in the workspace Cargo.toml file, # plus all the README.md files of the affected packages. - RUST_MIN_VER: "1.82" + RUST_MIN_VER: "1.85" # List of packages that can not target Wasm. NO_WASM_PKGS: "--exclude masonry --exclude xilem" # Only some of our examples support Android (primarily due to extra required boilerplate). diff --git a/Cargo.toml b/Cargo.toml index 66b75a51..6130e8ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,9 @@ members = [ ] [workspace.package] -edition = "2021" +edition = "2024" # Keep in sync with RUST_MIN_VER in .github/workflows/ci.yml, with the relevant README.md files. -rust-version = "1.82" +rust-version = "1.85" license = "Apache-2.0" repository = "https://github.com/linebender/xilem" homepage = "https://xilem.dev/" @@ -30,7 +30,7 @@ homepage = "https://xilem.dev/" [workspace.lints] # unsafe code is not allowed in Xilem or Masonry # We would like to set this to `forbid`, but we have to use `deny` because `android_activity` -# requires us to use the unsafe `#[no_mangle]` attribute +# requires us to use the `#[unsafe(no_mangle)]` attribute # (And cargo doesn't let us have platform specific lints here) rust.unsafe_code = "deny" diff --git a/README.md b/README.md index f5411c30..65366fd8 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ sudo apt-get install clang libwayland-dev libxkbcommon-x11-dev libvulkan-dev ## Minimum supported Rust Version (MSRV) -This version of Xilem has been verified to compile with **Rust 1.82** and later. +This version of Xilem has been verified to compile with **Rust 1.85** and later. Future versions of Xilem might increase the Rust version requirement. It will not be treated as a breaking change and as such can even happen with small patch releases. diff --git a/masonry/README.md b/masonry/README.md index b8e352f9..61abf823 100644 --- a/masonry/README.md +++ b/masonry/README.md @@ -124,7 +124,7 @@ Masonry apps currently ship with two debugging features built in: ## Minimum supported Rust Version (MSRV) -This version of Masonry has been verified to compile with **Rust 1.82** and later. +This version of Masonry has been verified to compile with **Rust 1.85** and later. Future versions of Masonry might increase the Rust version requirement. It will not be treated as a breaking change and as such can even happen with small patch releases. diff --git a/masonry/examples/calc_masonry.rs b/masonry/examples/calc_masonry.rs index 7cbd8b70..8b1f2c56 100644 --- a/masonry/examples/calc_masonry.rs +++ b/masonry/examples/calc_masonry.rs @@ -23,8 +23,8 @@ use masonry::dpi::LogicalSize; use masonry::kurbo::{Point, Size}; use masonry::peniko::Color; use masonry::widgets::{Align, CrossAxisAlignment, Flex, Label, RootWidget, SizedBox}; -use smallvec::{smallvec, SmallVec}; -use tracing::{trace, trace_span, Span}; +use smallvec::{SmallVec, smallvec}; +use tracing::{Span, trace, trace_span}; use vello::Scene; use winit::window::Window; diff --git a/masonry/examples/custom_widget.rs b/masonry/examples/custom_widget.rs index c54d9a00..66650020 100644 --- a/masonry/examples/custom_widget.rs +++ b/masonry/examples/custom_widget.rs @@ -23,9 +23,9 @@ use masonry::widgets::RootWidget; use parley::layout::Alignment; use parley::style::{FontFamily, FontStack, StyleProperty}; use smallvec::SmallVec; -use tracing::{trace_span, Span}; -use vello::peniko::{Fill, Image, ImageFormat}; +use tracing::{Span, trace_span}; use vello::Scene; +use vello::peniko::{Fill, Image, ImageFormat}; use winit::window::Window; struct Driver; diff --git a/masonry/src/app/mod.rs b/masonry/src/app/mod.rs index 68a30a3d..43d96947 100644 --- a/masonry/src/app/mod.rs +++ b/masonry/src/app/mod.rs @@ -10,7 +10,7 @@ mod tracing_backend; pub use app_driver::{AppDriver, DriverCtx}; pub use event_loop_runner::{ - run, run_with, EventLoop, EventLoopBuilder, EventLoopProxy, MasonryState, MasonryUserEvent, + EventLoop, EventLoopBuilder, EventLoopProxy, MasonryState, MasonryUserEvent, run, run_with, }; pub use render_root::{RenderRoot, RenderRootOptions, RenderRootSignal, WindowSizePolicy}; diff --git a/masonry/src/app/render_root.rs b/masonry/src/app/render_root.rs index 87a1f841..0ee7c363 100644 --- a/masonry/src/app/render_root.rs +++ b/masonry/src/app/render_root.rs @@ -8,10 +8,10 @@ use parley::fontique::{self, Collection, CollectionOptions, SourceCache}; use parley::{FontContext, LayoutContext}; use tracing::{info_span, warn}; use tree_arena::{ArenaMut, TreeArena}; +use vello::Scene; use vello::kurbo::{ Rect, {self}, }; -use vello::Scene; use winit::window::ResizeDirection; #[cfg(not(target_arch = "wasm32"))] @@ -19,6 +19,7 @@ use std::time::Instant; #[cfg(target_arch = "wasm32")] use web_time::Instant; +use crate::Handled; use crate::core::{ AccessEvent, Action, BrushIndex, PointerEvent, QueryCtx, TextEvent, Widget, WidgetArena, WidgetId, WidgetMut, WidgetPod, WidgetRef, WidgetState, WindowEvent, @@ -38,8 +39,7 @@ use crate::passes::update::{ run_update_pointer_pass, run_update_scroll_pass, run_update_stashed_pass, run_update_widget_tree_pass, }; -use crate::passes::{recurse_on_children, PassTracing}; -use crate::Handled; +use crate::passes::{PassTracing, recurse_on_children}; use cursor_icon::CursorIcon; /// We ensure that any valid initial IME area is sent to the platform by storing an invalid initial @@ -578,7 +578,9 @@ impl RenderRoot { } if self.root_state().needs_rewrite_passes() || self.global_state.needs_rewrite_passes() { - warn!("All rewrite passes have run {REWRITE_PASSES_MAX} times, but invalidations are still set"); + warn!( + "All rewrite passes have run {REWRITE_PASSES_MAX} times, but invalidations are still set" + ); // To avoid an infinite loop, we delay re-running the passes until the next frame. self.global_state .emit_signal(RenderRootSignal::RequestRedraw); diff --git a/masonry/src/app/tracing_backend.rs b/masonry/src/app/tracing_backend.rs index d1c014de..b77c4548 100644 --- a/masonry/src/app/tracing_backend.rs +++ b/masonry/src/app/tracing_backend.rs @@ -16,10 +16,10 @@ use std::time::UNIX_EPOCH; use time::macros::format_description; use tracing::subscriber::SetGlobalDefaultError; +use tracing_subscriber::EnvFilter; use tracing_subscriber::filter::LevelFilter; use tracing_subscriber::fmt::time::UtcTime; use tracing_subscriber::prelude::*; -use tracing_subscriber::EnvFilter; #[cfg(not(target_arch = "wasm32"))] /// Initialise tracing for a non-web platform with the given `default_level`. diff --git a/masonry/src/core/mod.rs b/masonry/src/core/mod.rs index 730bb21f..2980666f 100644 --- a/masonry/src/core/mod.rs +++ b/masonry/src/core/mod.rs @@ -30,7 +30,7 @@ pub use event::{ WindowTheme, }; pub use object_fit::ObjectFit; -pub use text::{render_text, ArcStr, BrushIndex, StyleProperty, StyleSet}; +pub use text::{ArcStr, BrushIndex, StyleProperty, StyleSet, render_text}; pub use widget::find_widget_at_pos; pub use widget::{AllowRawMut, FromDynWidget, Widget, WidgetId}; pub use widget_mut::WidgetMut; diff --git a/masonry/src/core/text.rs b/masonry/src/core/text.rs index c711c577..57095765 100644 --- a/masonry/src/core/text.rs +++ b/masonry/src/core/text.rs @@ -40,9 +40,9 @@ pub(crate) fn default_styles(styles: &mut StyleSet) { } use parley::{Layout, PositionedLayoutItem}; +use vello::Scene; use vello::kurbo::{Affine, Line, Stroke}; use vello::peniko::{Brush, Fill}; -use vello::Scene; /// A function that renders laid out glyphs to a [`Scene`]. /// diff --git a/masonry/src/core/widget.rs b/masonry/src/core/widget.rs index 1930e36c..b41c8ea0 100644 --- a/masonry/src/core/widget.rs +++ b/masonry/src/core/widget.rs @@ -10,15 +10,15 @@ use accesskit::{Node, Role}; use cursor_icon::CursorIcon; use smallvec::SmallVec; use tracing::field::DisplayValue; -use tracing::{trace_span, Span}; +use tracing::{Span, trace_span}; use vello::Scene; +use crate::AsAny; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, WidgetRef, }; use crate::kurbo::{Point, Size}; -use crate::AsAny; /// A unique identifier for a single [`Widget`]. /// diff --git a/masonry/src/core/widget_ref.rs b/masonry/src/core/widget_ref.rs index 995e1d49..1403d4db 100644 --- a/masonry/src/core/widget_ref.rs +++ b/masonry/src/core/widget_ref.rs @@ -174,7 +174,7 @@ impl WidgetRef<'_, dyn Widget> { mod tests { use assert_matches::assert_matches; - use crate::testing::{widget_ids, TestHarness, TestWidgetExt as _}; + use crate::testing::{TestHarness, TestWidgetExt as _, widget_ids}; use crate::widgets::{Button, Label}; #[test] diff --git a/masonry/src/passes/event.rs b/masonry/src/passes/event.rs index a8c53965..ead5a663 100644 --- a/masonry/src/passes/event.rs +++ b/masonry/src/passes/event.rs @@ -6,10 +6,10 @@ use tracing::{debug, info_span, trace}; use winit::event::ElementState; use winit::keyboard::{KeyCode, PhysicalKey}; +use crate::Handled; use crate::app::{RenderRoot, RenderRootSignal}; use crate::core::{AccessEvent, EventCtx, PointerEvent, TextEvent, Widget, WidgetId}; use crate::passes::{enter_span, merge_state_up}; -use crate::Handled; // --- MARK: HELPERS --- fn get_pointer_target( diff --git a/masonry/src/passes/layout.rs b/masonry/src/passes/layout.rs index 9f3b79d7..a1c18776 100644 --- a/masonry/src/passes/layout.rs +++ b/masonry/src/passes/layout.rs @@ -117,9 +117,7 @@ pub(crate) fn run_layout_on( if trace { trace!( "Computed layout: size={}, baseline={}, insets={:?}", - new_size, - state.item.baseline_offset, - state.item.paint_insets, + new_size, state.item.baseline_offset, state.item.paint_insets, ); } diff --git a/masonry/src/passes/paint.rs b/masonry/src/passes/paint.rs index c985fe0b..022e63ae 100644 --- a/masonry/src/passes/paint.rs +++ b/masonry/src/passes/paint.rs @@ -5,9 +5,9 @@ use std::collections::HashMap; use tracing::{info_span, trace}; use tree_arena::ArenaMut; +use vello::Scene; use vello::kurbo::Affine; use vello::peniko::{Color, Fill, Mix}; -use vello::Scene; use crate::app::{RenderRoot, RenderRootState}; use crate::core::{PaintCtx, Widget, WidgetId, WidgetState}; diff --git a/masonry/src/testing/harness.rs b/masonry/src/testing/harness.rs index f2ce5c0c..10c2104e 100644 --- a/masonry/src/testing/harness.rs +++ b/masonry/src/testing/harness.rs @@ -10,16 +10,17 @@ use cursor_icon::CursorIcon; use dpi::LogicalSize; use image::{DynamicImage, ImageReader, Rgba, RgbaImage}; use tracing::debug; -use vello::util::{block_on_wgpu, RenderContext}; use vello::RendererOptions; +use vello::util::{RenderContext, block_on_wgpu}; use wgpu::{ BufferDescriptor, BufferUsages, CommandEncoderDescriptor, Extent3d, ImageCopyBuffer, TextureDescriptor, TextureFormat, TextureUsages, }; use winit::event::Ime; +use crate::Handled; use crate::app::{ - try_init_test_tracing, RenderRoot, RenderRootOptions, RenderRootSignal, WindowSizePolicy, + RenderRoot, RenderRootOptions, RenderRootSignal, WindowSizePolicy, try_init_test_tracing, }; use crate::core::{ Action, PointerButton, PointerEvent, PointerState, TextEvent, Widget, WidgetId, WidgetMut, @@ -31,7 +32,6 @@ use crate::passes::anim::run_update_anim_pass; use crate::peniko::Color; use crate::testing::screenshots::get_image_diff; use crate::testing::snapshot_utils::get_cargo_workspace; -use crate::Handled; /// A safe headless environment to test widgets in. /// diff --git a/masonry/src/testing/helper_widgets.rs b/masonry/src/testing/helper_widgets.rs index 9c546582..28afd5de 100644 --- a/masonry/src/testing/helper_widgets.rs +++ b/masonry/src/testing/helper_widgets.rs @@ -17,14 +17,14 @@ use smallvec::SmallVec; use tracing::trace_span; use vello::Scene; +use crate::AsAny; use crate::core::{ - find_widget_at_pos, AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx, - PaintCtx, PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, - WidgetPod, WidgetRef, + AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx, PaintCtx, + PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetPod, + WidgetRef, find_widget_at_pos, }; use crate::kurbo::{Point, Size}; use crate::widgets::SizedBox; -use crate::AsAny; use cursor_icon::CursorIcon; pub type PointerEventFn = dyn FnMut(&mut S, &mut EventCtx, &PointerEvent); @@ -334,11 +334,7 @@ impl Widget for ModularWidget { } fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { - let Self { - ref mut state, - ref mut layout, - .. - } = self; + let Self { state, layout, .. } = self; layout .as_mut() .map(|f| f(state, ctx, bc)) diff --git a/masonry/src/testing/screenshots.rs b/masonry/src/testing/screenshots.rs index d600cef9..bb0987bc 100644 --- a/masonry/src/testing/screenshots.rs +++ b/masonry/src/testing/screenshots.rs @@ -4,7 +4,7 @@ //! Helper functions for writing snapshot tests and comparing images. use image::{GenericImageView as _, RgbImage}; -use nv_flip::{FlipImageRgb8, DEFAULT_PIXELS_PER_DEGREE}; +use nv_flip::{DEFAULT_PIXELS_PER_DEGREE, FlipImageRgb8}; #[cfg(docsrs)] #[doc(hidden)] diff --git a/masonry/src/util.rs b/masonry/src/util.rs index 4e097708..7b25b70d 100644 --- a/masonry/src/util.rs +++ b/masonry/src/util.rs @@ -6,11 +6,11 @@ use std::any::Any; use std::hash::Hash; +use vello::Scene; use vello::kurbo::{ Affine, Rect, Shape, Stroke, {self}, }; use vello::peniko::{BrushRef, Color, ColorStopsSource, Fill, Gradient}; -use vello::Scene; /// Panic in debug and `tracing::error` in release mode. /// @@ -56,11 +56,7 @@ impl Handled { impl From for Handled { /// Returns `Handled::Yes` if `handled` is true, and `Handled::No` otherwise. fn from(handled: bool) -> Self { - if handled { - Self::Yes - } else { - Self::No - } + if handled { Self::Yes } else { Self::No } } } diff --git a/masonry/src/widgets/align.rs b/masonry/src/widgets/align.rs index a85cdb0b..b651d2ff 100644 --- a/masonry/src/widgets/align.rs +++ b/masonry/src/widgets/align.rs @@ -9,8 +9,8 @@ // its computed size. See https://github.com/linebender/xilem/issues/378 use accesskit::{Node, Role}; -use smallvec::{smallvec, SmallVec}; -use tracing::{trace_span, Span}; +use smallvec::{SmallVec, smallvec}; +use tracing::{Span, trace_span}; use vello::Scene; use crate::core::{ diff --git a/masonry/src/widgets/button.rs b/masonry/src/widgets/button.rs index 12cd9777..44341c2c 100644 --- a/masonry/src/widgets/button.rs +++ b/masonry/src/widgets/button.rs @@ -4,8 +4,8 @@ //! A button widget. use accesskit::{Node, Role}; -use smallvec::{smallvec, SmallVec}; -use tracing::{trace, trace_span, Span}; +use smallvec::{SmallVec, smallvec}; +use tracing::{Span, trace, trace_span}; use vello::Scene; use crate::core::{ @@ -15,7 +15,7 @@ use crate::core::{ }; use crate::kurbo::{Insets, Size}; use crate::theme; -use crate::util::{fill_lin_gradient, stroke, UnitPoint}; +use crate::util::{UnitPoint, fill_lin_gradient, stroke}; use crate::widgets::Label; // The minimum padding added to a button. @@ -226,7 +226,7 @@ mod tests { use super::*; use crate::assert_render_snapshot; use crate::core::StyleProperty; - use crate::testing::{widget_ids, TestHarness, TestWidgetExt}; + use crate::testing::{TestHarness, TestWidgetExt, widget_ids}; use crate::theme::PRIMARY_LIGHT; #[test] diff --git a/masonry/src/widgets/checkbox.rs b/masonry/src/widgets/checkbox.rs index 1e700769..1c710044 100644 --- a/masonry/src/widgets/checkbox.rs +++ b/masonry/src/widgets/checkbox.rs @@ -4,10 +4,10 @@ //! A checkbox widget. use accesskit::{Node, Role, Toggled}; -use smallvec::{smallvec, SmallVec}; -use tracing::{trace, trace_span, Span}; -use vello::kurbo::{Affine, BezPath, Cap, Join, Size, Stroke}; +use smallvec::{SmallVec, smallvec}; +use tracing::{Span, trace, trace_span}; use vello::Scene; +use vello::kurbo::{Affine, BezPath, Cap, Join, Size, Stroke}; use crate::core::{ AccessCtx, AccessEvent, Action, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, @@ -15,7 +15,7 @@ use crate::core::{ WidgetPod, }; use crate::theme; -use crate::util::{fill_lin_gradient, stroke, UnitPoint}; +use crate::util::{UnitPoint, fill_lin_gradient, stroke}; use crate::widgets::Label; /// A checkbox that can be toggled. @@ -235,7 +235,7 @@ mod tests { use super::*; use crate::assert_render_snapshot; use crate::core::StyleProperty; - use crate::testing::{widget_ids, TestHarness, TestWidgetExt}; + use crate::testing::{TestHarness, TestWidgetExt, widget_ids}; use crate::theme::PRIMARY_LIGHT; #[test] diff --git a/masonry/src/widgets/flex.rs b/masonry/src/widgets/flex.rs index 047c6fcf..a69855fd 100644 --- a/masonry/src/widgets/flex.rs +++ b/masonry/src/widgets/flex.rs @@ -5,10 +5,10 @@ use accesskit::{Node, Role}; use smallvec::SmallVec; -use tracing::{trace_span, Span}; +use tracing::{Span, trace_span}; +use vello::Scene; use vello::kurbo::common::FloatExt; use vello::kurbo::{Affine, Line, Stroke, Vec2}; -use vello::Scene; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, @@ -893,7 +893,9 @@ fn new_flex_child(params: FlexParams, widget: WidgetPod) -> Child { flex, } } else { - tracing::warn!("Flex value should be > 0.0 (was {flex}). See the docs for masonry::widgets::Flex for more information"); + tracing::warn!( + "Flex value should be > 0.0 (was {flex}). See the docs for masonry::widgets::Flex for more information" + ); Child::Fixed { widget, alignment: params.alignment, diff --git a/masonry/src/widgets/grid.rs b/masonry/src/widgets/grid.rs index 2c44d647..c24a162f 100644 --- a/masonry/src/widgets/grid.rs +++ b/masonry/src/widgets/grid.rs @@ -3,9 +3,9 @@ use accesskit::{Node, Role}; use smallvec::SmallVec; -use tracing::{trace_span, Span}; -use vello::kurbo::{Affine, Line, Stroke}; +use tracing::{Span, trace_span}; use vello::Scene; +use vello::kurbo::{Affine, Line, Stroke}; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, diff --git a/masonry/src/widgets/image.rs b/masonry/src/widgets/image.rs index 05a31f45..14f80550 100644 --- a/masonry/src/widgets/image.rs +++ b/masonry/src/widgets/image.rs @@ -6,10 +6,10 @@ use accesskit::{Node, Role}; use smallvec::SmallVec; -use tracing::{trace_span, Span}; +use tracing::{Span, trace_span}; +use vello::Scene; use vello::kurbo::Affine; use vello::peniko::{BlendMode, Image as ImageBuf}; -use vello::Scene; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, ObjectFit, PaintCtx, PointerEvent, diff --git a/masonry/src/widgets/label.rs b/masonry/src/widgets/label.rs index 85d2cb6e..e902f6d4 100644 --- a/masonry/src/widgets/label.rs +++ b/masonry/src/widgets/label.rs @@ -11,15 +11,15 @@ use accesskit::{Node, NodeId, Role}; use parley::layout::Alignment; use parley::{Layout, LayoutAccessibility}; use smallvec::SmallVec; -use tracing::{trace_span, Span}; +use tracing::{Span, trace_span}; +use vello::Scene; use vello::kurbo::{Affine, Size}; use vello::peniko::{BlendMode, Brush}; -use vello::Scene; use crate::core::{ - default_styles, render_text, AccessCtx, AccessEvent, ArcStr, BoxConstraints, BrushIndex, - EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, RegisterCtx, StyleProperty, StyleSet, - TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, + AccessCtx, AccessEvent, ArcStr, BoxConstraints, BrushIndex, EventCtx, LayoutCtx, PaintCtx, + PointerEvent, QueryCtx, RegisterCtx, StyleProperty, StyleSet, TextEvent, Update, UpdateCtx, + Widget, WidgetId, WidgetMut, default_styles, render_text, }; use crate::theme; diff --git a/masonry/src/widgets/portal.rs b/masonry/src/widgets/portal.rs index 5d5b4f12..2909f33a 100644 --- a/masonry/src/widgets/portal.rs +++ b/masonry/src/widgets/portal.rs @@ -6,10 +6,10 @@ use std::ops::Range; use accesskit::{Node, Role}; -use smallvec::{smallvec, SmallVec}; -use tracing::{trace_span, Span}; -use vello::kurbo::{Point, Rect, Size, Vec2}; +use smallvec::{SmallVec, smallvec}; +use tracing::{Span, trace_span}; use vello::Scene; +use vello::kurbo::{Point, Rect, Size, Vec2}; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, FromDynWidget, LayoutCtx, @@ -482,7 +482,7 @@ mod tests { use super::*; use crate::assert_render_snapshot; - use crate::testing::{widget_ids, TestHarness}; + use crate::testing::{TestHarness, widget_ids}; use crate::widgets::{Button, Flex, SizedBox}; fn button(text: &'static str) -> impl Widget { diff --git a/masonry/src/widgets/progress_bar.rs b/masonry/src/widgets/progress_bar.rs index 7d548c02..35ddc94a 100644 --- a/masonry/src/widgets/progress_bar.rs +++ b/masonry/src/widgets/progress_bar.rs @@ -4,8 +4,8 @@ //! A progress bar widget. use accesskit::{Node, Role}; -use smallvec::{smallvec, SmallVec}; -use tracing::{trace_span, Span}; +use smallvec::{SmallVec, smallvec}; +use tracing::{Span, trace_span}; use vello::Scene; use crate::core::{ @@ -14,7 +14,7 @@ use crate::core::{ }; use crate::kurbo::{Point, Size}; use crate::theme; -use crate::util::{fill_lin_gradient, stroke, UnitPoint}; +use crate::util::{UnitPoint, fill_lin_gradient, stroke}; use crate::widgets::{Label, LineBreaking}; /// A progress bar. @@ -190,7 +190,7 @@ mod tests { use super::*; use crate::assert_render_snapshot; - use crate::testing::{widget_ids, TestHarness, TestWidgetExt}; + use crate::testing::{TestHarness, TestWidgetExt, widget_ids}; #[test] fn indeterminate_progressbar() { diff --git a/masonry/src/widgets/prose.rs b/masonry/src/widgets/prose.rs index 62a5f3fa..8eead044 100644 --- a/masonry/src/widgets/prose.rs +++ b/masonry/src/widgets/prose.rs @@ -4,10 +4,10 @@ #![warn(missing_docs)] use accesskit::{Node, Role}; -use smallvec::{smallvec, SmallVec}; -use tracing::{trace_span, Span}; -use vello::kurbo::{Point, Rect, Size}; +use smallvec::{SmallVec, smallvec}; +use tracing::{Span, trace_span}; use vello::Scene; +use vello::kurbo::{Point, Rect, Size}; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, @@ -161,8 +161,8 @@ impl Widget for Prose { // TODO - Add more tests #[cfg(test)] mod tests { - use parley::layout::Alignment; use parley::StyleProperty; + use parley::layout::Alignment; use vello::kurbo::Size; use super::*; diff --git a/masonry/src/widgets/root_widget.rs b/masonry/src/widgets/root_widget.rs index 1f53d77e..77ad0b84 100644 --- a/masonry/src/widgets/root_widget.rs +++ b/masonry/src/widgets/root_widget.rs @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 use accesskit::{Node, Role}; -use smallvec::{smallvec, SmallVec}; -use tracing::{trace_span, Span}; -use vello::kurbo::Point; +use smallvec::{SmallVec, smallvec}; +use tracing::{Span, trace_span}; use vello::Scene; +use vello::kurbo::Point; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, EventCtx, FromDynWidget, LayoutCtx, PaintCtx, diff --git a/masonry/src/widgets/scroll_bar.rs b/masonry/src/widgets/scroll_bar.rs index b1a34912..38b7e600 100644 --- a/masonry/src/widgets/scroll_bar.rs +++ b/masonry/src/widgets/scroll_bar.rs @@ -5,9 +5,9 @@ use accesskit::{Node, Role}; use smallvec::SmallVec; -use tracing::{trace_span, Span}; -use vello::kurbo::Rect; +use tracing::{Span, trace_span}; use vello::Scene; +use vello::kurbo::Rect; use crate::core::{ AccessCtx, AccessEvent, AllowRawMut, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, @@ -234,7 +234,7 @@ mod tests { use super::*; use crate::assert_render_snapshot; use crate::core::PointerButton; - use crate::testing::{widget_ids, TestHarness, TestWidgetExt}; + use crate::testing::{TestHarness, TestWidgetExt, widget_ids}; #[test] fn simple_scrollbar() { diff --git a/masonry/src/widgets/sized_box.rs b/masonry/src/widgets/sized_box.rs index 98b088d9..78162642 100644 --- a/masonry/src/widgets/sized_box.rs +++ b/masonry/src/widgets/sized_box.rs @@ -4,11 +4,11 @@ //! A widget with predefined size. use accesskit::{Node, Role}; -use smallvec::{smallvec, SmallVec}; -use tracing::{trace_span, warn, Span}; +use smallvec::{SmallVec, smallvec}; +use tracing::{Span, trace_span, warn}; +use vello::Scene; use vello::kurbo::{Affine, RoundedRectRadii}; use vello::peniko::{Brush, Fill}; -use vello::Scene; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, @@ -139,20 +139,12 @@ impl Padding { /// Get the padding to the left, given whether we're in a right-to-left context. pub const fn get_left(self, is_rtl: bool) -> f64 { - if is_rtl { - self.trailing - } else { - self.leading - } + if is_rtl { self.trailing } else { self.leading } } /// Get the padding to the right, given whether we're in a right-to-left context. pub const fn get_right(self, is_rtl: bool) -> f64 { - if is_rtl { - self.leading - } else { - self.trailing - } + if is_rtl { self.leading } else { self.trailing } } } diff --git a/masonry/src/widgets/spinner.rs b/masonry/src/widgets/spinner.rs index 2199cf55..7fe8afe1 100644 --- a/masonry/src/widgets/spinner.rs +++ b/masonry/src/widgets/spinner.rs @@ -7,9 +7,9 @@ use std::f64::consts::PI; use accesskit::{Node, Role}; use smallvec::SmallVec; -use tracing::{trace_span, Span}; -use vello::kurbo::{Affine, Cap, Line, Stroke}; +use tracing::{Span, trace_span}; use vello::Scene; +use vello::kurbo::{Affine, Cap, Line, Stroke}; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, diff --git a/masonry/src/widgets/split.rs b/masonry/src/widgets/split.rs index 29e30eeb..3614da67 100644 --- a/masonry/src/widgets/split.rs +++ b/masonry/src/widgets/split.rs @@ -4,8 +4,8 @@ //! A widget which splits an area in two, with a settable ratio, and optional draggable resizing. use accesskit::{Node, Role}; -use smallvec::{smallvec, SmallVec}; -use tracing::{trace_span, warn, Span}; +use smallvec::{SmallVec, smallvec}; +use tracing::{Span, trace_span, warn}; use vello::Scene; use crate::core::{ diff --git a/masonry/src/widgets/tests/layout.rs b/masonry/src/widgets/tests/layout.rs index 1a3a2c63..da3730ad 100644 --- a/masonry/src/widgets/tests/layout.rs +++ b/masonry/src/widgets/tests/layout.rs @@ -5,7 +5,7 @@ use vello::kurbo::{Insets, Size}; -use crate::testing::{widget_ids, ModularWidget, TestHarness, TestWidgetExt}; +use crate::testing::{ModularWidget, TestHarness, TestWidgetExt, widget_ids}; use crate::widgets::{Flex, SizedBox}; #[test] diff --git a/masonry/src/widgets/tests/lifecycle_basic.rs b/masonry/src/widgets/tests/lifecycle_basic.rs index 63ee23b6..cbdf59cf 100644 --- a/masonry/src/widgets/tests/lifecycle_basic.rs +++ b/masonry/src/widgets/tests/lifecycle_basic.rs @@ -6,7 +6,7 @@ use insta::assert_debug_snapshot; use crate::testing::{ - widget_ids, Record, Recording, ReplaceChild, TestHarness, TestWidgetExt as _, + Record, Recording, ReplaceChild, TestHarness, TestWidgetExt as _, widget_ids, }; use crate::widgets::{Flex, Label, SizedBox}; use crate::*; diff --git a/masonry/src/widgets/tests/lifecycle_disable.rs b/masonry/src/widgets/tests/lifecycle_disable.rs index 0f3acb1f..4f7f6e49 100644 --- a/masonry/src/widgets/tests/lifecycle_disable.rs +++ b/masonry/src/widgets/tests/lifecycle_disable.rs @@ -8,7 +8,7 @@ use std::rc::Rc; use smallvec::smallvec; -use crate::testing::{widget_ids, ModularWidget, TestHarness, TestWidgetExt as _}; +use crate::testing::{ModularWidget, TestHarness, TestWidgetExt as _, widget_ids}; use crate::widgets::Flex; use crate::*; @@ -112,7 +112,14 @@ fn disable_tree() { .collect() } - let [root_id, group_1_id, sub_group_1_id, group_2_id, leaf_1_id, leaf_2_id] = widget_ids(); + let [ + root_id, + group_1_id, + sub_group_1_id, + group_2_id, + leaf_1_id, + leaf_2_id, + ] = widget_ids(); // Our widget hierarchy is: // - root diff --git a/masonry/src/widgets/tests/lifecycle_focus.rs b/masonry/src/widgets/tests/lifecycle_focus.rs index 756bbc2c..2ca5228e 100644 --- a/masonry/src/widgets/tests/lifecycle_focus.rs +++ b/masonry/src/widgets/tests/lifecycle_focus.rs @@ -8,7 +8,7 @@ use std::rc::Rc; use smallvec::smallvec; -use crate::testing::{widget_ids, ModularWidget, ReplaceChild, TestHarness, TestWidgetExt as _}; +use crate::testing::{ModularWidget, ReplaceChild, TestHarness, TestWidgetExt as _, widget_ids}; use crate::widgets::Flex; use crate::*; diff --git a/masonry/src/widgets/tests/status_change.rs b/masonry/src/widgets/tests/status_change.rs index 865a8a10..e212c8bf 100644 --- a/masonry/src/widgets/tests/status_change.rs +++ b/masonry/src/widgets/tests/status_change.rs @@ -5,7 +5,7 @@ use assert_matches::assert_matches; use crate::core::{PointerButton, PointerEvent, PointerState, Update, WidgetId}; use crate::kurbo::Vec2; -use crate::testing::{widget_ids, Record, Recording, TestHarness, TestWidgetExt as _}; +use crate::testing::{Record, Recording, TestHarness, TestWidgetExt as _, widget_ids}; use crate::widgets::{Button, Flex, SizedBox}; fn next_pointer_event(recording: &Recording) -> Option { @@ -189,11 +189,7 @@ fn update_hovered_from_layout() { }) .layout_fn( move |collapsed, _ctx, _bc| { - if *collapsed { - Size::ZERO - } else { - BOX_SIZE - } + if *collapsed { Size::ZERO } else { BOX_SIZE } }, ); diff --git a/masonry/src/widgets/tests/widget_tree.rs b/masonry/src/widgets/tests/widget_tree.rs index 332f5aa6..4332e6db 100644 --- a/masonry/src/widgets/tests/widget_tree.rs +++ b/masonry/src/widgets/tests/widget_tree.rs @@ -3,7 +3,7 @@ use insta::assert_debug_snapshot; -use crate::testing::{widget_ids, TestHarness}; +use crate::testing::{TestHarness, widget_ids}; use crate::widgets::{Flex, Label}; #[test] diff --git a/masonry/src/widgets/text_area.rs b/masonry/src/widgets/text_area.rs index 6473268f..43279813 100644 --- a/masonry/src/widgets/text_area.rs +++ b/masonry/src/widgets/text_area.rs @@ -7,20 +7,20 @@ use std::mem::Discriminant; use std::time::Instant; use accesskit::{Node, NodeId, Role}; +use parley::PlainEditor; use parley::editor::{Generation, SplitString}; use parley::layout::Alignment; -use parley::PlainEditor; use smallvec::SmallVec; -use tracing::{trace_span, Span}; +use tracing::{Span, trace_span}; +use vello::Scene; use vello::kurbo::{Affine, Point, Rect, Size, Vec2}; use vello::peniko::{Brush, Fill}; -use vello::Scene; use winit::keyboard::{Key, NamedKey}; use crate::core::{ - default_styles, render_text, AccessCtx, AccessEvent, BoxConstraints, BrushIndex, EventCtx, - LayoutCtx, PaintCtx, PointerButton, PointerEvent, QueryCtx, RegisterCtx, StyleProperty, - TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, + AccessCtx, AccessEvent, BoxConstraints, BrushIndex, EventCtx, LayoutCtx, PaintCtx, + PointerButton, PointerEvent, QueryCtx, RegisterCtx, StyleProperty, TextEvent, Update, + UpdateCtx, Widget, WidgetId, WidgetMut, default_styles, render_text, }; use crate::widgets::Padding; use crate::{palette, theme}; diff --git a/masonry/src/widgets/textbox.rs b/masonry/src/widgets/textbox.rs index 45fdeb8c..dfd613c4 100644 --- a/masonry/src/widgets/textbox.rs +++ b/masonry/src/widgets/textbox.rs @@ -4,10 +4,10 @@ #![warn(missing_docs)] use accesskit::{Node, Role}; -use smallvec::{smallvec, SmallVec}; -use tracing::{trace_span, Span}; -use vello::kurbo::{Affine, Insets, Point, Rect, Size, Stroke}; +use smallvec::{SmallVec, smallvec}; +use tracing::{Span, trace_span}; use vello::Scene; +use vello::kurbo::{Affine, Insets, Point, Rect, Size, Stroke}; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, diff --git a/masonry/src/widgets/variable_label.rs b/masonry/src/widgets/variable_label.rs index 5e9d847d..d8106bb4 100644 --- a/masonry/src/widgets/variable_label.rs +++ b/masonry/src/widgets/variable_label.rs @@ -6,10 +6,10 @@ use std::cmp::Ordering; use accesskit::{Node, Role}; -use smallvec::{smallvec, SmallVec}; -use tracing::{trace_span, Span}; -use vello::kurbo::{Point, Size}; +use smallvec::{SmallVec, smallvec}; +use tracing::{Span, trace_span}; use vello::Scene; +use vello::kurbo::{Point, Size}; use crate::core::{ AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, diff --git a/xilem/README.md b/xilem/README.md index 362e8f2f..2a745b37 100644 --- a/xilem/README.md +++ b/xilem/README.md @@ -78,7 +78,7 @@ struct Counter { num: i32, } -fn app_logic(data: &mut Counter) -> impl WidgetView { +fn app_logic(data: &mut Counter) -> impl WidgetView + use<> { flex(( label(format!("{}", data.num)), button("increment", |data: &mut Counter| data.num += 1), @@ -149,7 +149,7 @@ You should also expect to use the adapters from Xilem Core, including: ## Minimum supported Rust Version (MSRV) -This version of Xilem has been verified to compile with **Rust 1.82** and later. +This version of Xilem has been verified to compile with **Rust 1.85** and later. Future versions of Xilem might increase the Rust version requirement. It will not be treated as a breaking change and as such can even happen with small patch releases. diff --git a/xilem/examples/calc.rs b/xilem/examples/calc.rs index c9fe679e..1a0f0975 100644 --- a/xilem/examples/calc.rs +++ b/xilem/examples/calc.rs @@ -9,10 +9,10 @@ use winit::dpi::LogicalSize; use winit::error::EventLoopError; use winit::window::Window; use xilem::view::{ - button, flex, grid, label, sized_box, Axis, Flex, FlexSequence, FlexSpacer, GridExt, - GridSequence, Label, + Axis, Flex, FlexSequence, FlexSpacer, GridExt, GridSequence, Label, button, flex, grid, label, + sized_box, }; -use xilem::{palette, EventLoop, EventLoopBuilder, WidgetView, Xilem}; +use xilem::{EventLoop, EventLoopBuilder, WidgetView, Xilem, palette}; #[derive(Copy, Clone)] enum MathOperator { @@ -200,7 +200,7 @@ fn num_row(nums: [&'static str; 3], row: i32) -> impl GridSequence { const DISPLAY_FONT_SIZE: f32 = 30.; const GRID_GAP: f64 = 2.; -fn app_logic(data: &mut Calculator) -> impl WidgetView { +fn app_logic(data: &mut Calculator) -> impl WidgetView + use<> { grid( ( // Display @@ -259,7 +259,7 @@ pub fn centered_flex_row>(sequence: Seq) -> Flex /// Returns a label intended to be used in the calculator's top display. /// The default text size is out of proportion for this use case. -fn display_label(text: &str) -> impl WidgetView { +fn display_label(text: &str) -> impl WidgetView + use<> { label(text).text_size(DISPLAY_FONT_SIZE) } @@ -332,7 +332,7 @@ fn main() -> Result<(), EventLoopError> { unsafe_code, reason = "We believe that there are no other declarations using this name in the compiled objects here" )] -#[no_mangle] +#[unsafe(no_mangle)] fn android_main(app: winit::platform::android::activity::AndroidApp) { use winit::platform::android::EventLoopBuilderExtAndroid; diff --git a/xilem/examples/components.rs b/xilem/examples/components.rs index 4c90752d..5c42e395 100644 --- a/xilem/examples/components.rs +++ b/xilem/examples/components.rs @@ -8,7 +8,7 @@ use masonry::widgets::MainAxisAlignment; use winit::error::EventLoopError; use xilem::core::lens; -use xilem::view::{button, flex, label, Axis}; +use xilem::view::{Axis, button, flex, label}; use xilem::{EventLoop, WidgetView, Xilem}; #[derive(Default)] @@ -17,7 +17,7 @@ struct AppState { global_count: i32, } -fn modular_counter(count: &mut i32) -> impl WidgetView { +fn modular_counter(count: &mut i32) -> impl WidgetView + use<> { flex(( label(format!("modularized count: {count}")), button("+", |count| *count += 1), @@ -25,7 +25,7 @@ fn modular_counter(count: &mut i32) -> impl WidgetView { )) } -fn app_logic(state: &mut AppState) -> impl WidgetView { +fn app_logic(state: &mut AppState) -> impl WidgetView + use<> { flex(( lens(modular_counter, state, |state| &mut state.modularized_count), button( diff --git a/xilem/examples/elm.rs b/xilem/examples/elm.rs index 38999d1d..1bc565d5 100644 --- a/xilem/examples/elm.rs +++ b/xilem/examples/elm.rs @@ -9,8 +9,8 @@ use masonry::widgets::{CrossAxisAlignment, MainAxisAlignment}; use winit::error::EventLoopError; -use xilem::core::{adapt, map_action, MessageResult}; -use xilem::view::{button, flex, label, Axis}; +use xilem::core::{MessageResult, adapt, map_action}; +use xilem::view::{Axis, button, flex, label}; use xilem::{EventLoop, WidgetView, Xilem}; #[derive(Default)] @@ -65,7 +65,7 @@ fn adapt_counter(count: i32) -> impl WidgetView { .direction(Axis::Horizontal) } -fn app_logic(state: &mut AppState) -> impl WidgetView { +fn app_logic(state: &mut AppState) -> impl WidgetView + use<> { flex(( map_action( elm_counter(state.map_action_count), diff --git a/xilem/examples/emoji_picker.rs b/xilem/examples/emoji_picker.rs index fdab7933..9a186410 100644 --- a/xilem/examples/emoji_picker.rs +++ b/xilem/examples/emoji_picker.rs @@ -8,11 +8,11 @@ use winit::error::EventLoopError; use xilem::core::map_state; use xilem::view::{ - button, flex, grid, label, prose, sized_box, Axis, FlexExt, FlexSpacer, GridExt, + Axis, FlexExt, FlexSpacer, GridExt, button, flex, grid, label, prose, sized_box, }; -use xilem::{palette, Color, EventLoop, EventLoopBuilder, WidgetView, Xilem}; +use xilem::{Color, EventLoop, EventLoopBuilder, WidgetView, Xilem, palette}; -fn app_logic(data: &mut EmojiPagination) -> impl WidgetView { +fn app_logic(data: &mut EmojiPagination) -> impl WidgetView + use<> { flex(( sized_box(flex(()).must_fill_major_axis(true)).height(50.), // Padding because of the info bar on Android flex(( @@ -43,7 +43,7 @@ fn app_logic(data: &mut EmojiPagination) -> impl WidgetView { .must_fill_major_axis(true) } -fn picker(data: &mut EmojiPagination) -> impl WidgetView { +fn picker(data: &mut EmojiPagination) -> impl WidgetView + use<> { let mut grid_items = vec![]; 'outer: for y in 0..data.size as usize { let row_idx = data.start_index + y * data.size as usize; @@ -186,7 +186,7 @@ fn main() -> Result<(), EventLoopError> { unsafe_code, reason = "We believe that there are no other declarations using this name in the compiled objects here" )] -#[no_mangle] +#[unsafe(no_mangle)] fn android_main(app: winit::platform::android::activity::AndroidApp) { use winit::platform::android::EventLoopBuilderExtAndroid; diff --git a/xilem/examples/external_event_loop.rs b/xilem/examples/external_event_loop.rs index 34c80f18..337b6f15 100644 --- a/xilem/examples/external_event_loop.rs +++ b/xilem/examples/external_event_loop.rs @@ -16,7 +16,7 @@ use winit::application::ApplicationHandler; use winit::error::EventLoopError; use winit::event::ElementState; use winit::keyboard::{KeyCode, PhysicalKey}; -use xilem::view::{button, flex, label, sized_box, Axis, Label}; +use xilem::view::{Axis, Label, button, flex, label, sized_box}; use xilem::{EventLoop, MasonryProxy, WidgetView, Xilem}; /// A component to make a bigger than usual button @@ -27,7 +27,7 @@ fn big_button( sized_box(button(label, callback)).width(40.).height(40.) } -fn app_logic(data: &mut i32) -> impl WidgetView { +fn app_logic(data: &mut i32) -> impl WidgetView + use<> { flex(( big_button("-", |data| { *data -= 1; diff --git a/xilem/examples/flex.rs b/xilem/examples/flex.rs index 32113d6c..d7486d54 100644 --- a/xilem/examples/flex.rs +++ b/xilem/examples/flex.rs @@ -6,7 +6,7 @@ #![expect(clippy::shadow_unrelated, reason = "Idiomatic for Xilem users")] use masonry::widgets::{CrossAxisAlignment, MainAxisAlignment}; use winit::error::EventLoopError; -use xilem::view::{button, flex, label, sized_box, Axis, FlexExt as _, FlexSpacer, Label}; +use xilem::view::{Axis, FlexExt as _, FlexSpacer, Label, button, flex, label, sized_box}; use xilem::{EventLoop, WidgetView, Xilem}; /// A component to make a bigger than usual button @@ -17,7 +17,7 @@ fn big_button( sized_box(button(label, callback)).width(40.).height(40.) } -fn app_logic(data: &mut i32) -> impl WidgetView { +fn app_logic(data: &mut i32) -> impl WidgetView + use<> { flex(( FlexSpacer::Fixed(30.0), big_button("-", |data| { diff --git a/xilem/examples/http_cats.rs b/xilem/examples/http_cats.rs index 9a3f7595..15edb69b 100644 --- a/xilem/examples/http_cats.rs +++ b/xilem/examples/http_cats.rs @@ -16,10 +16,10 @@ use winit::window::Window; use xilem::core::fork; use xilem::core::one_of::OneOf3; use xilem::view::{ - button, flex, image, inline_prose, portal, prose, sized_box, spinner, worker, zstack, Axis, - FlexExt, FlexSpacer, Padding, ZStackExt, + Axis, FlexExt, FlexSpacer, Padding, ZStackExt, button, flex, image, inline_prose, portal, + prose, sized_box, spinner, worker, zstack, }; -use xilem::{palette, EventLoop, EventLoopBuilder, TextAlignment, WidgetView, Xilem}; +use xilem::{EventLoop, EventLoopBuilder, TextAlignment, WidgetView, Xilem, palette}; /// The main state of the application. struct HttpCats { @@ -45,7 +45,7 @@ enum ImageState { } impl HttpCats { - fn view(&mut self) -> impl WidgetView { + fn view(&mut self) -> impl WidgetView + use<> { let left_column = sized_box(portal(flex(( prose("Status"), self.statuses @@ -163,7 +163,7 @@ async fn image_from_url(url: &str) -> anyhow::Result { } impl Status { - fn list_view(&mut self) -> impl WidgetView { + fn list_view(&mut self) -> impl WidgetView + use<> { let code = self.code; flex(( // TODO: Reduce allocations here? @@ -180,7 +180,7 @@ impl Status { .direction(Axis::Horizontal) } - fn details_view(&mut self) -> impl WidgetView { + fn details_view(&mut self) -> impl WidgetView + use<> { let image = match &self.image { ImageState::NotRequested => OneOf3::A( prose("Failed to start fetching image. This is a bug!") @@ -276,7 +276,7 @@ fn main() -> Result<(), EventLoopError> { unsafe_code, reason = "We believe that there are no other declarations using this name in the compiled objects here" )] -#[no_mangle] +#[unsafe(no_mangle)] fn android_main(app: winit::platform::android::activity::AndroidApp) { use winit::platform::android::EventLoopBuilderExtAndroid; diff --git a/xilem/examples/mason.rs b/xilem/examples/mason.rs index b0a8f492..5b2debe0 100644 --- a/xilem/examples/mason.rs +++ b/xilem/examples/mason.rs @@ -13,17 +13,17 @@ use winit::error::EventLoopError; use xilem::core::{fork, run_once}; use xilem::tokio::time; use xilem::view::{ - button, button_any_pointer, checkbox, flex, label, prose, task, textbox, Axis, FlexExt as _, - FlexSpacer, PointerButton, + Axis, FlexExt as _, FlexSpacer, PointerButton, button, button_any_pointer, checkbox, flex, + label, prose, task, textbox, }; use xilem::{ - palette, Color, EventLoop, EventLoopBuilder, FontWeight, TextAlignment, WidgetView, Xilem, + Color, EventLoop, EventLoopBuilder, FontWeight, TextAlignment, WidgetView, Xilem, palette, }; const LOREM: &str = r"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi cursus mi sed euismod euismod. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nullam placerat efficitur tellus at semper. Morbi ac risus magna. Donec ut cursus ex. Etiam quis posuere tellus. Mauris posuere dui et turpis mollis, vitae luctus tellus consectetur. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu facilisis nisl. Phasellus in viverra dolor, vitae facilisis est. Maecenas malesuada massa vel ultricies feugiat. Vivamus venenatis et nibh nec pharetra. Phasellus vestibulum elit enim, nec scelerisque orci faucibus id. Vivamus consequat purus sit amet orci egestas, non iaculis massa porttitor. Vestibulum ut eros leo. In fermentum convallis magna in finibus. Donec justo leo, maximus ac laoreet id, volutpat ut elit. Mauris sed leo non neque laoreet faucibus. Aliquam orci arcu, faucibus in molestie eget, ornare non dui. Donec volutpat nulla in fringilla elementum. Aliquam vitae ante egestas ligula tempus vestibulum sit amet sed ante. "; -fn app_logic(data: &mut AppData) -> impl WidgetView { +fn app_logic(data: &mut AppData) -> impl WidgetView + use<> { // here's some logic, deriving state for the view from our state let count = data.count; let button_label = if count == 1 { @@ -119,7 +119,7 @@ fn app_logic(data: &mut AppData) -> impl WidgetView { ) } -fn toggleable(data: &mut AppData) -> impl WidgetView { +fn toggleable(data: &mut AppData) -> impl WidgetView + use<> { if data.active { fork( flex(( @@ -173,7 +173,7 @@ fn main() -> Result<(), EventLoopError> { unsafe_code, reason = "We believe that there are no other declarations using this name in the compiled objects here" )] -#[no_mangle] +#[unsafe(no_mangle)] fn android_main(app: winit::platform::android::activity::AndroidApp) { use winit::platform::android::EventLoopBuilderExtAndroid; diff --git a/xilem/examples/memoization.rs b/xilem/examples/memoization.rs index cbdafe45..70e3a08a 100644 --- a/xilem/examples/memoization.rs +++ b/xilem/examples/memoization.rs @@ -42,7 +42,7 @@ fn increase_button(state: &mut AppState) -> Arc> { // This is the alternative with Memoize // Note how this requires a closure that returns the memoized view, while Arc does not -fn decrease_button(state: &AppState) -> impl WidgetView { +fn decrease_button(state: &AppState) -> impl WidgetView + use<> { memoize(state.count, |count| { button( format!("decrease the count: {count}"), @@ -57,7 +57,7 @@ fn reset_button() -> impl WidgetView { frozen(|| button("reset", |data: &mut AppState| data.count = 0)) } -fn app_logic(state: &mut AppState) -> impl WidgetView { +fn app_logic(state: &mut AppState) -> impl WidgetView + use<> { flex(( increase_button(state), decrease_button(state), diff --git a/xilem/examples/state_machine.rs b/xilem/examples/state_machine.rs index 22007fc8..74fd1400 100644 --- a/xilem/examples/state_machine.rs +++ b/xilem/examples/state_machine.rs @@ -28,7 +28,7 @@ enum IsEven { Success, } -fn state_machine(app_data: &mut StateMachine) -> impl WidgetView { +fn state_machine(app_data: &mut StateMachine) -> impl WidgetView + use<> { match app_data.state { // The first time we use `OneOf` in a conditional statement, we need // to specify the number of `OneOf` variants used - 3 in this case. @@ -59,7 +59,7 @@ fn sequence_button(value: &'static str, target_state: IsEven) -> impl WidgetView }) } -fn app_logic(app_data: &mut StateMachine) -> impl WidgetView { +fn app_logic(app_data: &mut StateMachine) -> impl WidgetView + use<> { flex(( button("Reset", |app_data: &mut StateMachine| { app_data.history.clear(); diff --git a/xilem/examples/stopwatch.rs b/xilem/examples/stopwatch.rs index 89badbcb..b012e52c 100644 --- a/xilem/examples/stopwatch.rs +++ b/xilem/examples/stopwatch.rs @@ -17,7 +17,7 @@ use winit::error::EventLoopError; use winit::window::Window; use xilem::core::fork; use xilem::core::one_of::Either; -use xilem::view::{button, flex, label, task, FlexSequence, FlexSpacer}; +use xilem::view::{FlexSequence, FlexSpacer, button, flex, label, task}; use xilem::{WidgetView, Xilem}; /// The state of the entire application. @@ -108,7 +108,7 @@ fn get_formatted_duration(dur: Duration) -> String { format!("{hours}:{minutes:0>2}:{seconds:0>4.1}") } -fn app_logic(data: &mut Stopwatch) -> impl WidgetView { +fn app_logic(data: &mut Stopwatch) -> impl WidgetView + use<> { fork( flex(( FlexSpacer::Fixed(5.0), @@ -139,7 +139,7 @@ fn app_logic(data: &mut Stopwatch) -> impl WidgetView { } /// Creates a list of items that shows the lap number, split time, and total cumulative time. -fn laps_section(data: &mut Stopwatch) -> impl FlexSequence { +fn laps_section(data: &mut Stopwatch) -> impl FlexSequence + use<> { let mut items = Vec::new(); let mut total_dur = Duration::ZERO; let current_lap = data.completed_lap_splits.len(); @@ -176,7 +176,7 @@ fn single_lap( .must_fill_major_axis(true) } -fn start_stop_button(data: &mut Stopwatch) -> impl WidgetView { +fn start_stop_button(data: &mut Stopwatch) -> impl WidgetView + use<> { if data.active { Either::A(button("Stop", |data: &mut Stopwatch| { data.stop(); @@ -188,7 +188,7 @@ fn start_stop_button(data: &mut Stopwatch) -> impl WidgetView { } } -fn lap_reset_button(data: &mut Stopwatch) -> impl WidgetView { +fn lap_reset_button(data: &mut Stopwatch) -> impl WidgetView + use<> { if data.active { Either::A(button(" Lap ", |data: &mut Stopwatch| { data.lap(); @@ -240,7 +240,7 @@ fn main() -> Result<(), EventLoopError> { unsafe_code, reason = "We believe that there are no other declarations using this name in the compiled objects here" )] -#[no_mangle] +#[unsafe(no_mangle)] fn android_main(app: winit::platform::android::activity::AndroidApp) { use winit::platform::android::EventLoopBuilderExtAndroid; diff --git a/xilem/examples/to_do_mvc.rs b/xilem/examples/to_do_mvc.rs index 0f51f8b0..1e5ae0bf 100644 --- a/xilem/examples/to_do_mvc.rs +++ b/xilem/examples/to_do_mvc.rs @@ -8,7 +8,7 @@ #![expect(clippy::shadow_unrelated, reason = "Idiomatic for Xilem users")] use winit::error::EventLoopError; -use xilem::view::{button, checkbox, flex, textbox, Axis, FlexSpacer}; +use xilem::view::{Axis, FlexSpacer, button, checkbox, flex, textbox}; use xilem::{EventLoop, EventLoopBuilder, WidgetView, Xilem}; struct Task { @@ -33,7 +33,7 @@ impl TaskList { } } -fn app_logic(task_list: &mut TaskList) -> impl WidgetView { +fn app_logic(task_list: &mut TaskList) -> impl WidgetView + use<> { let input_box = textbox( task_list.next_task.clone(), |task_list: &mut TaskList, new_value| { @@ -117,7 +117,7 @@ fn main() -> Result<(), EventLoopError> { unsafe_code, reason = "We believe that there are no other declarations using this name in the compiled objects here" )] -#[no_mangle] +#[unsafe(no_mangle)] fn android_main(app: winit::platform::android::activity::AndroidApp) { use winit::platform::android::EventLoopBuilderExtAndroid; diff --git a/xilem/examples/transforms.rs b/xilem/examples/transforms.rs index edfc8648..aa27fc9b 100644 --- a/xilem/examples/transforms.rs +++ b/xilem/examples/transforms.rs @@ -6,7 +6,7 @@ use std::f64::consts::{PI, TAU}; use winit::error::EventLoopError; -use xilem::view::{button, grid, label, sized_box, transformed, GridExt as _}; +use xilem::view::{GridExt as _, button, grid, label, sized_box, transformed}; use xilem::{Affine, Color, EventLoop, Vec2, WidgetView, Xilem}; struct TransformsGame { @@ -16,7 +16,7 @@ struct TransformsGame { } impl TransformsGame { - fn view(&mut self) -> impl WidgetView { + fn view(&mut self) -> impl WidgetView + use<> { let rotation_correct = (self.rotation % TAU).abs() < 0.001; let scale_correct = self.scale >= 0.99 && self.scale <= 1.01; let translation_correct = self.translation.x == 0.0 && self.translation.y == 0.0; diff --git a/xilem/examples/variable_clock.rs b/xilem/examples/variable_clock.rs index aac357d8..5ff0e668 100644 --- a/xilem/examples/variable_clock.rs +++ b/xilem/examples/variable_clock.rs @@ -12,10 +12,10 @@ use time::{OffsetDateTime, UtcOffset}; use winit::error::EventLoopError; use xilem::core::fork; use xilem::view::{ - button, flex, inline_prose, label, portal, prose, sized_box, task, variable_label, Axis, - FlexExt, FlexSpacer, + Axis, FlexExt, FlexSpacer, button, flex, inline_prose, label, portal, prose, sized_box, task, + variable_label, }; -use xilem::{palette, EventLoop, EventLoopBuilder, FontWeight, WidgetView, Xilem}; +use xilem::{EventLoop, EventLoopBuilder, FontWeight, WidgetView, Xilem, palette}; /// The state of the application, owned by Xilem and updated by the callbacks below. struct Clocks { @@ -35,7 +35,7 @@ struct TimeZone { offset: UtcOffset, } -fn app_logic(data: &mut Clocks) -> impl WidgetView { +fn app_logic(data: &mut Clocks) -> impl WidgetView + use<> { let view = flex(( // HACK: We add a spacer at the top for Android. See https://github.com/rust-windowing/winit/issues/2308 FlexSpacer::Fixed(40.), @@ -68,7 +68,7 @@ fn app_logic(data: &mut Clocks) -> impl WidgetView { /// Shows the current system time on a best-effort basis. // TODO: Maybe make this have a larger font size? -fn local_time(data: &mut Clocks) -> impl WidgetView { +fn local_time(data: &mut Clocks) -> impl WidgetView + use<> { let (error_view, offset) = if let Ok(offset) = data.local_offset { (None, offset) } else { @@ -112,7 +112,7 @@ fn controls() -> impl WidgetView { impl TimeZone { /// Display this timezone as a row, designed to be shown in a list of time zones. - fn view(&self, data: &mut Clocks) -> impl WidgetView { + fn view(&self, data: &mut Clocks) -> impl WidgetView + use<> { let date_time_in_self = data.now_utc.to_offset(self.offset); sized_box(flex(( flex(( @@ -252,7 +252,7 @@ fn main() -> Result<(), EventLoopError> { unsafe_code, reason = "We believe that there are no other declarations using this name in the compiled objects here" )] -#[no_mangle] +#[unsafe(no_mangle)] fn android_main(app: winit::platform::android::activity::AndroidApp) { use winit::platform::android::EventLoopBuilderExtAndroid; diff --git a/xilem/examples/widgets.rs b/xilem/examples/widgets.rs index 2e166b15..f0b84d9a 100644 --- a/xilem/examples/widgets.rs +++ b/xilem/examples/widgets.rs @@ -8,7 +8,7 @@ use masonry::dpi::LogicalSize; use winit::error::EventLoopError; use winit::window::Window; use xilem::core::adapt; -use xilem::view::{button, checkbox, flex, flex_item, progress_bar, sized_box, Axis, FlexSpacer}; +use xilem::view::{Axis, FlexSpacer, button, checkbox, flex, flex_item, progress_bar, sized_box}; use xilem::{Color, WidgetView, Xilem}; const SPACER_WIDTH: f64 = 10.; @@ -36,7 +36,7 @@ fn progress_bar_view(data: Option) -> impl WidgetView> { }, ), button("change progress", |state: &mut Option| match state { - Some(ref mut v) => *v = (*v + 0.1).rem_euclid(1.), + Some(v) => *v = (*v + 0.1).rem_euclid(1.), None => *state = Some(0.5), }), )) @@ -66,7 +66,7 @@ fn border_box( } /// Top-level view -fn app_logic(data: &mut WidgetGallery) -> impl WidgetView { +fn app_logic(data: &mut WidgetGallery) -> impl WidgetView + use<> { // Use a `sized_box` to pad the window contents sized_box( flex(( @@ -121,7 +121,7 @@ fn main() -> Result<(), EventLoopError> { unsafe_code, reason = "We believe that there are no other declarations using this name in the compiled objects here" )] -#[no_mangle] +#[unsafe(no_mangle)] fn android_main(app: winit::platform::android::activity::AndroidApp) { use winit::platform::android::EventLoopBuilderExtAndroid; diff --git a/xilem/src/any_view.rs b/xilem/src/any_view.rs index 4a15d30e..c34bffa0 100644 --- a/xilem/src/any_view.rs +++ b/xilem/src/any_view.rs @@ -7,8 +7,8 @@ use masonry::core::{ PointerEvent, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, WidgetMut, WidgetPod, }; use masonry::kurbo::{Point, Size}; -use smallvec::{smallvec, SmallVec}; -use tracing::{trace_span, Span}; +use smallvec::{SmallVec, smallvec}; +use tracing::{Span, trace_span}; use vello::Scene; use crate::core::{AnyElement, AnyView, Mut, SuperElement}; diff --git a/xilem/src/driver.rs b/xilem/src/driver.rs index 72b58077..b34b86ee 100644 --- a/xilem/src/driver.rs +++ b/xilem/src/driver.rs @@ -91,7 +91,9 @@ where &mut self.state, ) } else { - tracing::error!("Got action {action:?} for unknown widget. Did you forget to use `with_action_widget`?"); + tracing::error!( + "Got action {action:?} for unknown widget. Did you forget to use `with_action_widget`?" + ); return; }; let rebuild = match message_result { diff --git a/xilem/src/lib.rs b/xilem/src/lib.rs index f5b2c78a..0854292f 100644 --- a/xilem/src/lib.rs +++ b/xilem/src/lib.rs @@ -34,7 +34,7 @@ //! num: i32, //! } //! -//! fn app_logic(data: &mut Counter) -> impl WidgetView { +//! fn app_logic(data: &mut Counter) -> impl WidgetView + use<> { //! flex(( //! label(format!("{}", data.num)), //! button("increment", |data: &mut Counter| data.num += 1), @@ -136,7 +136,7 @@ use std::sync::Arc; use masonry::core::{FromDynWidget, Widget, WidgetId, WidgetMut, WidgetPod}; use masonry::dpi::LogicalSize; use masonry::widgets::RootWidget; -use view::{transformed, Transformed}; +use view::{Transformed, transformed}; use winit::error::EventLoopError; use winit::window::{Window, WindowAttributes}; @@ -146,8 +146,8 @@ use crate::core::{ }; pub use masonry::app::{EventLoop, EventLoopBuilder}; pub use masonry::kurbo::{Affine, Vec2}; -pub use masonry::parley::style::FontWeight; pub use masonry::parley::Alignment as TextAlignment; +pub use masonry::parley::style::FontWeight; pub use masonry::peniko::Color; pub use masonry::widgets::LineBreaking; pub use masonry::{dpi, palette}; @@ -164,7 +164,7 @@ mod one_of; pub mod view; pub use any_view::AnyWidgetView; -pub use driver::{async_action, MasonryDriver, MasonryProxy, ASYNC_MARKER_WIDGET}; +pub use driver::{ASYNC_MARKER_WIDGET, MasonryDriver, MasonryProxy, async_action}; /// Runtime builder. #[must_use = "A Xilem app does nothing unless ran."] @@ -376,7 +376,7 @@ pub trait WidgetView: /// ``` /// use xilem::{view::label, WidgetView}; /// - /// # fn view() -> impl WidgetView { + /// # fn view() -> impl WidgetView + use { /// label("a label").boxed() /// # } /// diff --git a/xilem/src/one_of.rs b/xilem/src/one_of.rs index 1574b0b1..dd4132a4 100644 --- a/xilem/src/one_of.rs +++ b/xilem/src/one_of.rs @@ -9,24 +9,24 @@ use masonry::core::{ PointerEvent, RegisterCtx, TextEvent, Widget, WidgetId, WidgetPod, }; use masonry::kurbo::{Point, Size}; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use vello::Scene; -use crate::core::one_of::OneOf; use crate::core::Mut; +use crate::core::one_of::OneOf; use crate::{Pod, ViewCtx}; impl< - A: Widget + FromDynWidget + ?Sized, - B: Widget + FromDynWidget + ?Sized, - C: Widget + FromDynWidget + ?Sized, - D: Widget + FromDynWidget + ?Sized, - E: Widget + FromDynWidget + ?Sized, - F: Widget + FromDynWidget + ?Sized, - G: Widget + FromDynWidget + ?Sized, - H: Widget + FromDynWidget + ?Sized, - I: Widget + FromDynWidget + ?Sized, - > + A: Widget + FromDynWidget + ?Sized, + B: Widget + FromDynWidget + ?Sized, + C: Widget + FromDynWidget + ?Sized, + D: Widget + FromDynWidget + ?Sized, + E: Widget + FromDynWidget + ?Sized, + F: Widget + FromDynWidget + ?Sized, + G: Widget + FromDynWidget + ?Sized, + H: Widget + FromDynWidget + ?Sized, + I: Widget + FromDynWidget + ?Sized, +> crate::core::one_of::OneOfCtx< Pod, Pod, @@ -171,16 +171,16 @@ pub enum OneOfWidget< } impl< - A: Widget + FromDynWidget + ?Sized, - B: Widget + FromDynWidget + ?Sized, - C: Widget + FromDynWidget + ?Sized, - D: Widget + FromDynWidget + ?Sized, - E: Widget + FromDynWidget + ?Sized, - F: Widget + FromDynWidget + ?Sized, - G: Widget + FromDynWidget + ?Sized, - H: Widget + FromDynWidget + ?Sized, - I: Widget + FromDynWidget + ?Sized, - > Widget for OneOfWidget + A: Widget + FromDynWidget + ?Sized, + B: Widget + FromDynWidget + ?Sized, + C: Widget + FromDynWidget + ?Sized, + D: Widget + FromDynWidget + ?Sized, + E: Widget + FromDynWidget + ?Sized, + F: Widget + FromDynWidget + ?Sized, + G: Widget + FromDynWidget + ?Sized, + H: Widget + FromDynWidget + ?Sized, + I: Widget + FromDynWidget + ?Sized, +> Widget for OneOfWidget { fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} diff --git a/xilem/src/view/flex.rs b/xilem/src/view/flex.rs index d5ea8fe4..6f21e489 100644 --- a/xilem/src/view/flex.rs +++ b/xilem/src/view/flex.rs @@ -30,7 +30,7 @@ use crate::{AnyWidgetView, Pod, ViewCtx, WidgetView}; /// sized_box(button(label, callback)).width(40.).height(40.) /// } /// -/// fn app_logic(data: &mut i32) -> impl WidgetView { +/// fn app_logic(data: &mut i32) -> impl WidgetView + use<> { /// flex(( /// FlexSpacer::Fixed(30.0), /// big_button("-", |data| { diff --git a/xilem/src/view/image.rs b/xilem/src/view/image.rs index 4db67d91..4765e8a8 100644 --- a/xilem/src/view/image.rs +++ b/xilem/src/view/image.rs @@ -80,7 +80,9 @@ impl View for Image { message: DynMessage, _: &mut State, ) -> MessageResult { - tracing::error!("Message arrived in Label::message, but Label doesn't consume any messages, this is a bug"); + tracing::error!( + "Message arrived in Label::message, but Label doesn't consume any messages, this is a bug" + ); MessageResult::Stale(message) } } diff --git a/xilem/src/view/label.rs b/xilem/src/view/label.rs index a1ecde56..8c308073 100644 --- a/xilem/src/view/label.rs +++ b/xilem/src/view/label.rs @@ -162,7 +162,9 @@ impl View for Label { message: DynMessage, _app_state: &mut State, ) -> MessageResult { - tracing::error!("Message arrived in Label::message, but Label doesn't consume any messages, this is a bug"); + tracing::error!( + "Message arrived in Label::message, but Label doesn't consume any messages, this is a bug" + ); MessageResult::Stale(message) } } diff --git a/xilem/src/view/progress_bar.rs b/xilem/src/view/progress_bar.rs index ac3cc611..7d69ccae 100644 --- a/xilem/src/view/progress_bar.rs +++ b/xilem/src/view/progress_bar.rs @@ -46,7 +46,9 @@ impl View for ProgressBar { message: DynMessage, _app_state: &mut State, ) -> MessageResult { - tracing::error!("Message arrived in ProgressBar::message, but ProgressBar doesn't consume any messages, this is a bug"); + tracing::error!( + "Message arrived in ProgressBar::message, but ProgressBar doesn't consume any messages, this is a bug" + ); MessageResult::Stale(message) } } diff --git a/xilem/src/view/prose.rs b/xilem/src/view/prose.rs index 4efe9ef6..dd538dd4 100644 --- a/xilem/src/view/prose.rs +++ b/xilem/src/view/prose.rs @@ -129,7 +129,9 @@ impl View for Prose { message: DynMessage, _app_state: &mut State, ) -> MessageResult { - tracing::error!("Message arrived in Prose::message, but Prose doesn't consume any messages, this is a bug"); + tracing::error!( + "Message arrived in Prose::message, but Prose doesn't consume any messages, this is a bug" + ); MessageResult::Stale(message) } } diff --git a/xilem/src/view/spinner.rs b/xilem/src/view/spinner.rs index 3e8e5393..505cf323 100644 --- a/xilem/src/view/spinner.rs +++ b/xilem/src/view/spinner.rs @@ -86,7 +86,9 @@ impl View for Spinner { message: DynMessage, _: &mut State, ) -> MessageResult { - tracing::error!("Message arrived in Label::message, but Label doesn't consume any messages, this is a bug"); + tracing::error!( + "Message arrived in Label::message, but Label doesn't consume any messages, this is a bug" + ); MessageResult::Stale(message) } } diff --git a/xilem/src/view/task.rs b/xilem/src/view/task.rs index 97b09a22..70688c72 100644 --- a/xilem/src/view/task.rs +++ b/xilem/src/view/task.rs @@ -7,11 +7,11 @@ use std::sync::Arc; use tokio::task::JoinHandle; +use crate::ViewCtx; use crate::core::{ DynMessage, Message, MessageProxy, MessageResult, Mut, NoElement, View, ViewId, ViewMarker, ViewPathTracker, }; -use crate::ViewCtx; /// Launch a task which will run until the view is no longer in the tree. /// `init_future` is given a [`MessageProxy`], which it will store in the future it returns. diff --git a/xilem/src/view/variable_label.rs b/xilem/src/view/variable_label.rs index aee3264f..def9f031 100644 --- a/xilem/src/view/variable_label.rs +++ b/xilem/src/view/variable_label.rs @@ -2,13 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 use masonry::core::ArcStr; -use masonry::parley::style::{FontStack, FontWeight}; use masonry::parley::Alignment as TextAlignment; +use masonry::parley::style::{FontStack, FontWeight}; use masonry::widgets; use vello::peniko::Brush; use xilem_core::ViewPathTracker; -use super::{label, Label}; +use super::{Label, label}; use crate::core::{DynMessage, Mut, ViewMarker}; use crate::{MessageResult, Pod, View, ViewCtx, ViewId}; @@ -150,7 +150,9 @@ impl View for VariableLabel { assert_eq!(first.routing_id(), 0); self.label.message(&mut (), remainder, message, app_state) } else { - tracing::error!("Message arrived in Label::message, but Label doesn't consume any messages, this is a bug"); + tracing::error!( + "Message arrived in Label::message, but Label doesn't consume any messages, this is a bug" + ); MessageResult::Stale(message) } } diff --git a/xilem/src/view/worker.rs b/xilem/src/view/worker.rs index 1902dc34..2b6e467e 100644 --- a/xilem/src/view/worker.rs +++ b/xilem/src/view/worker.rs @@ -8,11 +8,11 @@ use std::sync::Arc; use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender}; use tokio::task::JoinHandle; +use crate::ViewCtx; use crate::core::{ DynMessage, Message, MessageProxy, MessageResult, Mut, NoElement, View, ViewId, ViewMarker, ViewPathTracker, }; -use crate::ViewCtx; /// Launch a task which will run until the view is no longer in the tree. /// diff --git a/xilem_core/README.md b/xilem_core/README.md index 83bb5976..d8d8e548 100644 --- a/xilem_core/README.md +++ b/xilem_core/README.md @@ -47,7 +47,7 @@ If you wish to use Xilem Core in environments where an allocator is not availabl ## Minimum supported Rust Version (MSRV) -This version of Xilem Core has been verified to compile with **Rust 1.82** and later. +This version of Xilem Core has been verified to compile with **Rust 1.85** and later. Future versions of Xilem Core might increase the Rust version requirement. It will not be treated as a breaking change and as such can even happen with small patch releases. diff --git a/xilem_core/examples/filesystem.rs b/xilem_core/examples/filesystem.rs index a081628e..1285e183 100644 --- a/xilem_core/examples/filesystem.rs +++ b/xilem_core/examples/filesystem.rs @@ -17,14 +17,14 @@ enum State { Complex(String), } -fn complex_state(value: &str) -> impl FileView { +fn complex_state(value: &str) -> impl FileView + use<> { File { name: value.to_string(), contents: value.to_string(), } } -fn app_logic(state: &mut State) -> impl FileView { +fn app_logic(state: &mut State) -> impl FileView + use<> { let res: DynFileView = match state { State::Setup => Box::new(File { name: "file1.txt".into(), diff --git a/xilem_core/examples/user_interface.rs b/xilem_core/examples/user_interface.rs index bbc61e93..55364c39 100644 --- a/xilem_core/examples/user_interface.rs +++ b/xilem_core/examples/user_interface.rs @@ -10,7 +10,7 @@ use xilem_core::{ ViewPathTracker, }; -fn app_logic(_: &mut u32) -> impl WidgetView { +fn app_logic(_: &mut u32) -> impl WidgetView + use<> { Button {} } diff --git a/xilem_core/src/any_view.rs b/xilem_core/src/any_view.rs index a8393972..59b205e7 100644 --- a/xilem_core/src/any_view.rs +++ b/xilem_core/src/any_view.rs @@ -173,12 +173,8 @@ pub struct AnyViewState { generation: u64, } -impl ViewMarker - for dyn AnyView -{ -} -impl View - for dyn AnyView +impl ViewMarker for dyn AnyView {} +impl View for dyn AnyView where // Element must be `static` so it can be downcasted Element: ViewElement + 'static, diff --git a/xilem_core/src/docs.rs b/xilem_core/src/docs.rs index 214d44a7..29d53cfc 100644 --- a/xilem_core/src/docs.rs +++ b/xilem_core/src/docs.rs @@ -35,7 +35,7 @@ //! # struct InterestingPrimitive; //! ``` -use crate::{run_once, View, ViewPathTracker}; +use crate::{View, ViewPathTracker, run_once}; /// A type used for documentation #[derive(Debug)] @@ -68,7 +68,7 @@ impl DocsView for V where V: View(_: &mut State) -> impl DocsView { +pub fn some_component(_: &mut State) -> impl DocsView + use { // The view which does nothing already exists in `run_once`. run_once(|| {}) } diff --git a/xilem_core/src/lib.rs b/xilem_core/src/lib.rs index d0fc939c..a1806237 100644 --- a/xilem_core/src/lib.rs +++ b/xilem_core/src/lib.rs @@ -41,8 +41,8 @@ pub use view::{View, ViewId, ViewMarker, ViewPathTracker}; mod views; pub use views::{ - adapt, fork, frozen, lens, map_action, map_state, memoize, one_of, run_once, run_once_raw, - Adapt, AdaptThunk, Fork, Frozen, MapAction, MapState, Memoize, OrphanView, RunOnce, + Adapt, AdaptThunk, Fork, Frozen, MapAction, MapState, Memoize, OrphanView, RunOnce, adapt, + fork, frozen, lens, map_action, map_state, memoize, one_of, run_once, run_once_raw, }; mod message; diff --git a/xilem_core/src/views/mod.rs b/xilem_core/src/views/mod.rs index cae48f24..792e8719 100644 --- a/xilem_core/src/views/mod.rs +++ b/xilem_core/src/views/mod.rs @@ -2,22 +2,22 @@ // SPDX-License-Identifier: Apache-2.0 mod run_once; -pub use run_once::{run_once, run_once_raw, RunOnce}; +pub use run_once::{RunOnce, run_once, run_once_raw}; mod adapt; -pub use adapt::{adapt, Adapt, AdaptThunk}; +pub use adapt::{Adapt, AdaptThunk, adapt}; mod map_state; -pub use map_state::{lens, map_state, MapState}; +pub use map_state::{MapState, lens, map_state}; mod map_action; -pub use map_action::{map_action, MapAction}; +pub use map_action::{MapAction, map_action}; mod fork; -pub use fork::{fork, Fork}; +pub use fork::{Fork, fork}; mod memoize; -pub use memoize::{frozen, memoize, Frozen, Memoize}; +pub use memoize::{Frozen, Memoize, frozen, memoize}; pub mod one_of; diff --git a/xilem_core/src/views/one_of.rs b/xilem_core/src/views/one_of.rs index da96e589..c78d3ec4 100644 --- a/xilem_core/src/views/one_of.rs +++ b/xilem_core/src/views/one_of.rs @@ -286,7 +286,7 @@ where let id = ViewId::new(view_state.generation); // If both elements are of the same type, do a simple rebuild match (self, prev, &mut view_state.inner_state) { - (Self::A(this), Self::A(prev), OneOf::A(ref mut state)) => { + (Self::A(this), Self::A(prev), OneOf::A(state)) => { ctx.with_id(id, |ctx| { Context::with_downcast_a(&mut element, |element| { this.rebuild(prev, state, ctx, element); @@ -294,7 +294,7 @@ where }); return; } - (Self::B(this), Self::B(prev), OneOf::B(ref mut state)) => { + (Self::B(this), Self::B(prev), OneOf::B(state)) => { ctx.with_id(id, |ctx| { Context::with_downcast_b(&mut element, |element| { this.rebuild(prev, state, ctx, element); @@ -302,7 +302,7 @@ where }); return; } - (Self::C(this), Self::C(prev), OneOf::C(ref mut state)) => { + (Self::C(this), Self::C(prev), OneOf::C(state)) => { ctx.with_id(id, |ctx| { Context::with_downcast_c(&mut element, |element| { this.rebuild(prev, state, ctx, element); @@ -310,7 +310,7 @@ where }); return; } - (Self::D(this), Self::D(prev), OneOf::D(ref mut state)) => { + (Self::D(this), Self::D(prev), OneOf::D(state)) => { ctx.with_id(id, |ctx| { Context::with_downcast_d(&mut element, |element| { this.rebuild(prev, state, ctx, element); @@ -318,7 +318,7 @@ where }); return; } - (Self::E(this), Self::E(prev), OneOf::E(ref mut state)) => { + (Self::E(this), Self::E(prev), OneOf::E(state)) => { ctx.with_id(id, |ctx| { Context::with_downcast_e(&mut element, |element| { this.rebuild(prev, state, ctx, element); @@ -326,7 +326,7 @@ where }); return; } - (Self::F(this), Self::F(prev), OneOf::F(ref mut state)) => { + (Self::F(this), Self::F(prev), OneOf::F(state)) => { ctx.with_id(id, |ctx| { Context::with_downcast_f(&mut element, |element| { this.rebuild(prev, state, ctx, element); @@ -334,7 +334,7 @@ where }); return; } - (Self::G(this), Self::G(prev), OneOf::G(ref mut state)) => { + (Self::G(this), Self::G(prev), OneOf::G(state)) => { ctx.with_id(id, |ctx| { Context::with_downcast_g(&mut element, |element| { this.rebuild(prev, state, ctx, element); @@ -342,7 +342,7 @@ where }); return; } - (Self::H(this), Self::H(prev), OneOf::H(ref mut state)) => { + (Self::H(this), Self::H(prev), OneOf::H(state)) => { ctx.with_id(id, |ctx| { Context::with_downcast_h(&mut element, |element| { this.rebuild(prev, state, ctx, element); @@ -350,7 +350,7 @@ where }); return; } - (Self::I(this), Self::I(prev), OneOf::I(ref mut state)) => { + (Self::I(this), Self::I(prev), OneOf::I(state)) => { ctx.with_id(id, |ctx| { Context::with_downcast_i(&mut element, |element| { this.rebuild(prev, state, ctx, element); @@ -363,47 +363,47 @@ where // We're changing the type of the view. Teardown the old version ctx.with_id(id, |ctx| match (prev, &mut view_state.inner_state) { - (Self::A(prev), OneOf::A(ref mut state)) => { + (Self::A(prev), OneOf::A(state)) => { Context::with_downcast_a(&mut element, |element| { prev.teardown(state, ctx, element); }); } - (Self::B(prev), OneOf::B(ref mut state)) => { + (Self::B(prev), OneOf::B(state)) => { Context::with_downcast_b(&mut element, |element| { prev.teardown(state, ctx, element); }); } - (Self::C(prev), OneOf::C(ref mut state)) => { + (Self::C(prev), OneOf::C(state)) => { Context::with_downcast_c(&mut element, |element| { prev.teardown(state, ctx, element); }); } - (Self::D(prev), OneOf::D(ref mut state)) => { + (Self::D(prev), OneOf::D(state)) => { Context::with_downcast_d(&mut element, |element| { prev.teardown(state, ctx, element); }); } - (Self::E(prev), OneOf::E(ref mut state)) => { + (Self::E(prev), OneOf::E(state)) => { Context::with_downcast_e(&mut element, |element| { prev.teardown(state, ctx, element); }); } - (Self::F(prev), OneOf::F(ref mut state)) => { + (Self::F(prev), OneOf::F(state)) => { Context::with_downcast_f(&mut element, |element| { prev.teardown(state, ctx, element); }); } - (Self::G(prev), OneOf::G(ref mut state)) => { + (Self::G(prev), OneOf::G(state)) => { Context::with_downcast_g(&mut element, |element| { prev.teardown(state, ctx, element); }); } - (Self::H(prev), OneOf::H(ref mut state)) => { + (Self::H(prev), OneOf::H(state)) => { Context::with_downcast_h(&mut element, |element| { prev.teardown(state, ctx, element); }); } - (Self::I(prev), OneOf::I(ref mut state)) => { + (Self::I(prev), OneOf::I(state)) => { Context::with_downcast_i(&mut element, |element| { prev.teardown(state, ctx, element); }); @@ -468,47 +468,47 @@ where ) { ctx.with_id(ViewId::new(view_state.generation), |ctx| { match (self, &mut view_state.inner_state) { - (Self::A(v), OneOf::A(ref mut state)) => { + (Self::A(v), OneOf::A(state)) => { Context::with_downcast_a(&mut element, |element| { v.teardown(state, ctx, element); }); } - (Self::B(v), OneOf::B(ref mut state)) => { + (Self::B(v), OneOf::B(state)) => { Context::with_downcast_b(&mut element, |element| { v.teardown(state, ctx, element); }); } - (Self::C(v), OneOf::C(ref mut state)) => { + (Self::C(v), OneOf::C(state)) => { Context::with_downcast_c(&mut element, |element| { v.teardown(state, ctx, element); }); } - (Self::D(v), OneOf::D(ref mut state)) => { + (Self::D(v), OneOf::D(state)) => { Context::with_downcast_d(&mut element, |element| { v.teardown(state, ctx, element); }); } - (Self::E(v), OneOf::E(ref mut state)) => { + (Self::E(v), OneOf::E(state)) => { Context::with_downcast_e(&mut element, |element| { v.teardown(state, ctx, element); }); } - (Self::F(v), OneOf::F(ref mut state)) => { + (Self::F(v), OneOf::F(state)) => { Context::with_downcast_f(&mut element, |element| { v.teardown(state, ctx, element); }); } - (Self::G(v), OneOf::G(ref mut state)) => { + (Self::G(v), OneOf::G(state)) => { Context::with_downcast_g(&mut element, |element| { v.teardown(state, ctx, element); }); } - (Self::H(v), OneOf::H(ref mut state)) => { + (Self::H(v), OneOf::H(state)) => { Context::with_downcast_h(&mut element, |element| { v.teardown(state, ctx, element); }); } - (Self::I(v), OneOf::I(ref mut state)) => { + (Self::I(v), OneOf::I(state)) => { Context::with_downcast_i(&mut element, |element| { v.teardown(state, ctx, element); }); @@ -533,15 +533,15 @@ where return MessageResult::Stale(message); } match (self, &mut view_state.inner_state) { - (Self::A(v), OneOf::A(ref mut state)) => v.message(state, rest, message, app_state), - (Self::B(v), OneOf::B(ref mut state)) => v.message(state, rest, message, app_state), - (Self::C(v), OneOf::C(ref mut state)) => v.message(state, rest, message, app_state), - (Self::D(v), OneOf::D(ref mut state)) => v.message(state, rest, message, app_state), - (Self::E(v), OneOf::E(ref mut state)) => v.message(state, rest, message, app_state), - (Self::F(v), OneOf::F(ref mut state)) => v.message(state, rest, message, app_state), - (Self::G(v), OneOf::G(ref mut state)) => v.message(state, rest, message, app_state), - (Self::H(v), OneOf::H(ref mut state)) => v.message(state, rest, message, app_state), - (Self::I(v), OneOf::I(ref mut state)) => v.message(state, rest, message, app_state), + (Self::A(v), OneOf::A(state)) => v.message(state, rest, message, app_state), + (Self::B(v), OneOf::B(state)) => v.message(state, rest, message, app_state), + (Self::C(v), OneOf::C(state)) => v.message(state, rest, message, app_state), + (Self::D(v), OneOf::D(state)) => v.message(state, rest, message, app_state), + (Self::E(v), OneOf::E(state)) => v.message(state, rest, message, app_state), + (Self::F(v), OneOf::F(state)) => v.message(state, rest, message, app_state), + (Self::G(v), OneOf::G(state)) => v.message(state, rest, message, app_state), + (Self::H(v), OneOf::H(state)) => v.message(state, rest, message, app_state), + (Self::I(v), OneOf::I(state)) => v.message(state, rest, message, app_state), _ => unreachable!(), } } diff --git a/xilem_web/README.md b/xilem_web/README.md index 9535b19c..bca8ad59 100644 --- a/xilem_web/README.md +++ b/xilem_web/README.md @@ -37,7 +37,7 @@ use xilem_web::{ App, }; -fn app_logic(clicks: &mut u32) -> impl HtmlDivElement { +fn app_logic(clicks: &mut u32) -> impl HtmlDivElement + use<> { div(( button(format!("clicked {clicks} times")).on_click(|clicks: &mut u32, _event| *clicks += 1), (*clicks >= 5).then_some(p("Huzzah, clicked at least 5 times")), @@ -52,7 +52,7 @@ pub fn main() { ## Minimum supported Rust Version (MSRV) -This version of Xilem Web has been verified to compile with **Rust 1.82** and later. +This version of Xilem Web has been verified to compile with **Rust 1.85** and later. Future versions of Xilem Web might increase the Rust version requirement. It will not be treated as a breaking change and as such can even happen with small patch releases. diff --git a/xilem_web/src/concurrent/mod.rs b/xilem_web/src/concurrent/mod.rs index d8708cd7..60d8b96b 100644 --- a/xilem_web/src/concurrent/mod.rs +++ b/xilem_web/src/concurrent/mod.rs @@ -4,10 +4,10 @@ //! Async views, allowing concurrent operations, like fetching data from a server mod task; -pub use task::{task, task_raw, ShutdownSignal, Task, TaskProxy}; +pub use task::{ShutdownSignal, Task, TaskProxy, task, task_raw}; mod interval; -pub use interval::{interval, Interval}; +pub use interval::{Interval, interval}; mod memoized_await; -pub use memoized_await::{memoized_await, MemoizedAwait}; +pub use memoized_await::{MemoizedAwait, memoized_await}; diff --git a/xilem_web/src/concurrent/task.rs b/xilem_web/src/concurrent/task.rs index 53f39bc6..df2c038d 100644 --- a/xilem_web/src/concurrent/task.rs +++ b/xilem_web/src/concurrent/task.rs @@ -5,8 +5,8 @@ use std::future::Future; use std::marker::PhantomData; use std::rc::Rc; -use futures::channel::oneshot; use futures::FutureExt; +use futures::channel::oneshot; use wasm_bindgen::UnwrapThrowExt; use wasm_bindgen_futures::spawn_local; diff --git a/xilem_web/src/context.rs b/xilem_web/src/context.rs index 029406f5..055864f8 100644 --- a/xilem_web/src/context.rs +++ b/xilem_web/src/context.rs @@ -6,10 +6,10 @@ use std::rc::Rc; use wasm_bindgen_futures::spawn_local; +use crate::Message; use crate::app::{AppMessage, AppRunner}; use crate::core::{ViewId, ViewPathTracker}; use crate::vecmap::VecMap; -use crate::Message; /// A thunk to send messages to the views, it's being used for example in event callbacks pub struct MessageThunk { diff --git a/xilem_web/src/elements.rs b/xilem_web/src/elements.rs index aa8099d9..b387a9b0 100644 --- a/xilem_web/src/elements.rs +++ b/xilem_web/src/elements.rs @@ -14,7 +14,7 @@ use crate::core::{AppendVec, ElementSplice, MessageResult, Mut, View, ViewId, Vi use crate::modifiers::Children; use crate::vec_splice::VecSplice; use crate::{ - document, AnyPod, DomFragment, DomNode, DynMessage, FromWithContext, Pod, ViewCtx, HTML_NS, + AnyPod, DomFragment, DomNode, DynMessage, FromWithContext, HTML_NS, Pod, ViewCtx, document, }; // sealed, because this should only cover `ViewSequences` with the blanket impl below diff --git a/xilem_web/src/events.rs b/xilem_web/src/events.rs index 5661febd..42cecb10 100644 --- a/xilem_web/src/events.rs +++ b/xilem_web/src/events.rs @@ -5,8 +5,8 @@ use std::borrow::Cow; use std::marker::PhantomData; use wasm_bindgen::prelude::Closure; -use wasm_bindgen::{throw_str, JsCast, UnwrapThrowExt}; -use web_sys::{js_sys, AddEventListenerOptions}; +use wasm_bindgen::{JsCast, UnwrapThrowExt, throw_str}; +use web_sys::{AddEventListenerOptions, js_sys}; use crate::core::{MessageResult, Mut, View, ViewId, ViewMarker, ViewPathTracker}; use crate::{DomView, DynMessage, OptionalAction, ViewCtx}; diff --git a/xilem_web/src/interfaces.rs b/xilem_web/src/interfaces.rs index d209f038..ae49a4ff 100644 --- a/xilem_web/src/interfaces.rs +++ b/xilem_web/src/interfaces.rs @@ -18,7 +18,7 @@ use wasm_bindgen::JsCast; use crate::modifiers::{Attr, Class, ClassIter, Rotate, Scale, ScaleValue, Style, StyleIter}; use crate::props::{WithElementProps, WithHtmlInputElementProps}; -use crate::{events, DomNode, DomView, IntoAttributeValue, OptionalAction, Pointer, PointerMsg}; +use crate::{DomNode, DomView, IntoAttributeValue, OptionalAction, Pointer, PointerMsg, events}; macro_rules! event_handler_mixin { ($(($event_ty: ident, $fn_name:ident, $event:expr, $web_sys_event_type:ident),)*) => { @@ -807,10 +807,10 @@ use crate::modifiers::html_input_element; // #[cfg(feature = "HtmlInputElement")] pub trait HtmlInputElement: HtmlElement< - State, - Action, - DomNode: DomNode + AsRef, -> + State, + Action, + DomNode: DomNode + AsRef, + > { /// See for more details. /// diff --git a/xilem_web/src/lib.rs b/xilem_web/src/lib.rs index 9166a2c9..d1a2f554 100644 --- a/xilem_web/src/lib.rs +++ b/xilem_web/src/lib.rs @@ -78,7 +78,7 @@ pub mod props; pub mod svg; pub use self::after_update::{ - after_build, after_rebuild, before_teardown, AfterBuild, AfterRebuild, BeforeTeardown, + AfterBuild, AfterRebuild, BeforeTeardown, after_build, after_rebuild, before_teardown, }; pub use self::app::App; pub use self::attribute_value::{AttributeValue, IntoAttributeValue}; @@ -89,7 +89,7 @@ pub use self::optional_action::{Action, OptionalAction}; pub use self::pod::{AnyPod, Pod, PodFlags, PodMut}; pub use self::pointer::{Pointer, PointerDetails, PointerMsg}; -pub use templated::{templated, Templated}; +pub use templated::{Templated, templated}; pub use xilem_core as core; diff --git a/xilem_web/src/modifiers/class.rs b/xilem_web/src/modifiers/class.rs index be650ef3..e96e3ac2 100644 --- a/xilem_web/src/modifiers/class.rs +++ b/xilem_web/src/modifiers/class.rs @@ -7,7 +7,7 @@ use std::marker::PhantomData; use wasm_bindgen::{JsCast, UnwrapThrowExt}; use crate::core::{MessageResult, Mut, View, ViewElement, ViewId, ViewMarker}; -use crate::diff::{diff_iters, Diff}; +use crate::diff::{Diff, diff_iters}; use crate::modifiers::{Modifier, WithModifier}; use crate::vecmap::VecMap; use crate::{DomView, DynMessage, ViewCtx}; diff --git a/xilem_web/src/modifiers/overwrite.rs b/xilem_web/src/modifiers/overwrite.rs index 92a3d40b..fbaba952 100644 --- a/xilem_web/src/modifiers/overwrite.rs +++ b/xilem_web/src/modifiers/overwrite.rs @@ -184,10 +184,10 @@ macro_rules! overwrite_bool_modifier_view { State: 'static, Action: 'static, V: $crate::DomView< - State, - Action, - Element: $crate::modifiers::WithModifier, - >, + State, + Action, + Element: $crate::modifiers::WithModifier, + >, for<'a> ::Mut<'a>: $crate::modifiers::WithModifier, { diff --git a/xilem_web/src/modifiers/style.rs b/xilem_web/src/modifiers/style.rs index e5e7ffbb..2ed032fb 100644 --- a/xilem_web/src/modifiers/style.rs +++ b/xilem_web/src/modifiers/style.rs @@ -11,7 +11,7 @@ use wasm_bindgen::{JsCast, UnwrapThrowExt}; use super::{Modifier, WithModifier}; use crate::core::{MessageResult, Mut, View, ViewElement, ViewId, ViewMarker}; -use crate::diff::{diff_iters, Diff}; +use crate::diff::{Diff, diff_iters}; use crate::vecmap::VecMap; use crate::{DomView, DynMessage, ViewCtx}; diff --git a/xilem_web/src/one_of.rs b/xilem_web/src/one_of.rs index 3a3cc5bd..46b09372 100644 --- a/xilem_web/src/one_of.rs +++ b/xilem_web/src/one_of.rs @@ -3,8 +3,8 @@ use wasm_bindgen::UnwrapThrowExt; -use crate::core::one_of::{OneOf, OneOfCtx, PhantomElementCtx}; use crate::core::Mut; +use crate::core::one_of::{OneOf, OneOfCtx, PhantomElementCtx}; use crate::{DomNode, Pod, PodFlags, PodMut, ViewCtx}; impl diff --git a/xilem_web/src/pointer.rs b/xilem_web/src/pointer.rs index 6c179d4b..dc265dc9 100644 --- a/xilem_web/src/pointer.rs +++ b/xilem_web/src/pointer.rs @@ -7,7 +7,7 @@ use std::marker::PhantomData; use peniko::kurbo::Point; use wasm_bindgen::prelude::Closure; -use wasm_bindgen::{throw_str, JsCast, UnwrapThrowExt}; +use wasm_bindgen::{JsCast, UnwrapThrowExt, throw_str}; use web_sys::PointerEvent; use crate::core::{MessageResult, Mut, View, ViewId, ViewMarker, ViewPathTracker}; diff --git a/xilem_web/src/props/element.rs b/xilem_web/src/props/element.rs index c6b6cc31..5c306068 100644 --- a/xilem_web/src/props/element.rs +++ b/xilem_web/src/props/element.rs @@ -4,7 +4,7 @@ use wasm_bindgen::{JsCast, UnwrapThrowExt}; use crate::modifiers::{Attributes, Children, Classes, Modifier, Styles}; -use crate::{document, AnyPod, Pod, PodFlags, ViewCtx}; +use crate::{AnyPod, Pod, PodFlags, ViewCtx, document}; // Lazy access to attributes etc. to avoid allocating unnecessary memory when it isn't needed // Benchmarks have shown, that this can significantly increase performance and reduce memory usage... diff --git a/xilem_web/src/props/html_input_element.rs b/xilem_web/src/props/html_input_element.rs index ee9ff111..d50238f4 100644 --- a/xilem_web/src/props/html_input_element.rs +++ b/xilem_web/src/props/html_input_element.rs @@ -5,7 +5,7 @@ use wasm_bindgen::JsCast as _; use super::WithElementProps; use crate::modifiers::html_input_element::{Checked, DefaultChecked, Disabled, Multiple, Required}; -use crate::{props, FromWithContext, Pod, PodFlags, ViewCtx}; +use crate::{FromWithContext, Pod, PodFlags, ViewCtx, props}; /// Props specific to an input element. pub struct HtmlInputElement { @@ -123,12 +123,12 @@ pub trait WithHtmlInputElementProps: { } impl< - T: WithElementProps - + AsMut - + AsMut - + AsMut - + AsMut - + AsMut, - > WithHtmlInputElementProps for T + T: WithElementProps + + AsMut + + AsMut + + AsMut + + AsMut + + AsMut, +> WithHtmlInputElementProps for T { } diff --git a/xilem_web/src/svg/common_attrs.rs b/xilem_web/src/svg/common_attrs.rs index 9334e45f..09ecf971 100644 --- a/xilem_web/src/svg/common_attrs.rs +++ b/xilem_web/src/svg/common_attrs.rs @@ -4,7 +4,7 @@ use std::fmt::Write as _; use std::marker::PhantomData; -use peniko::{kurbo, Brush}; +use peniko::{Brush, kurbo}; use crate::core::{MessageResult, Mut, View, ViewElement, ViewId, ViewMarker}; use crate::modifiers::{AttributeModifier, Attributes, Modifier, WithModifier}; @@ -86,11 +86,7 @@ fn opacity_attr_modifier(attr: &'static str, brush: &Brush) -> AttributeModifier let opacity = match brush { Brush::Solid(color) => { let a = color.components[3]; - if a < 1.0 { - Some(a as f64) - } else { - None - } + if a < 1.0 { Some(a as f64) } else { None } } _ => None, }; @@ -295,8 +291,8 @@ where #[cfg(test)] mod tests { - use peniko::color::palette; use peniko::Brush; + use peniko::color::palette; use super::brush_to_string; diff --git a/xilem_web/src/svg/kurbo_shape.rs b/xilem_web/src/svg/kurbo_shape.rs index 4af8fdc6..4dd7f964 100644 --- a/xilem_web/src/svg/kurbo_shape.rs +++ b/xilem_web/src/svg/kurbo_shape.rs @@ -7,7 +7,7 @@ use peniko::kurbo::{BezPath, Circle, Line, Rect}; use crate::core::{MessageResult, Mut, OrphanView, ViewId}; use crate::modifiers::{Attributes, WithModifier}; -use crate::{DynMessage, FromWithContext, Pod, ViewCtx, SVG_NS}; +use crate::{DynMessage, FromWithContext, Pod, SVG_NS, ViewCtx}; fn create_element( name: &str, diff --git a/xilem_web/src/svg/mod.rs b/xilem_web/src/svg/mod.rs index c8d54bb9..0d8745b4 100644 --- a/xilem_web/src/svg/mod.rs +++ b/xilem_web/src/svg/mod.rs @@ -6,6 +6,6 @@ pub(crate) mod common_attrs; pub(crate) mod kurbo_shape; -pub use common_attrs::{fill, stroke, Fill, Stroke}; +pub use common_attrs::{Fill, Stroke, fill, stroke}; pub use peniko; pub use peniko::kurbo; diff --git a/xilem_web/web_examples/counter/src/main.rs b/xilem_web/web_examples/counter/src/main.rs index aa1027b9..1d5e71b0 100644 --- a/xilem_web/web_examples/counter/src/main.rs +++ b/xilem_web/web_examples/counter/src/main.rs @@ -6,7 +6,7 @@ use xilem_web::elements::html as el; use xilem_web::interfaces::{Element, HtmlButtonElement}; -use xilem_web::{document_body, App, DomFragment}; +use xilem_web::{App, DomFragment, document_body}; #[derive(Default)] struct AppState { @@ -51,12 +51,12 @@ fn btn( } /// And functions that return a sequence of views. -fn huzzah(state: &mut AppState) -> impl DomFragment { +fn huzzah(state: &mut AppState) -> impl DomFragment + use<> { (state.clicks >= 5).then_some("Huzzah, clicked at least 5 times") } /// Even the root `app_logic` can return a sequence of views -fn app_logic(state: &mut AppState) -> impl DomFragment { +fn app_logic(state: &mut AppState) -> impl DomFragment + use<> { ( el::span(format!("clicked {} times", state.clicks)).class(state.class), el::br(()), diff --git a/xilem_web/web_examples/counter_custom_element/src/main.rs b/xilem_web/web_examples/counter_custom_element/src/main.rs index f36df837..3665b53e 100644 --- a/xilem_web/web_examples/counter_custom_element/src/main.rs +++ b/xilem_web/web_examples/counter_custom_element/src/main.rs @@ -7,7 +7,7 @@ use xilem_web::elements::custom_element; use xilem_web::interfaces::{Element, HtmlElement}; -use xilem_web::{document_body, App, DomView}; +use xilem_web::{App, DomView, document_body}; #[derive(Default)] struct AppState { @@ -35,7 +35,7 @@ fn btn( }) } -fn app_logic(state: &mut AppState) -> impl DomView { +fn app_logic(state: &mut AppState) -> impl DomView + use<> { custom_element( "div", ( diff --git a/xilem_web/web_examples/elm/src/main.rs b/xilem_web/web_examples/elm/src/main.rs index 9ccc7f00..e62edd2c 100644 --- a/xilem_web/web_examples/elm/src/main.rs +++ b/xilem_web/web_examples/elm/src/main.rs @@ -10,7 +10,7 @@ use xilem_web::core::map_action; use xilem_web::elements::html as el; use xilem_web::interfaces::{Element, HtmlDivElement}; -use xilem_web::{document_body, Action, App}; +use xilem_web::{Action, App, document_body}; #[derive(Debug, Default)] struct Model { @@ -34,7 +34,7 @@ fn update(model: &mut Model, message: Message) { log::debug!("Model updated: {model:?}"); } -fn app_logic(model: &mut Model) -> impl HtmlDivElement { +fn app_logic(model: &mut Model) -> impl HtmlDivElement + use<> { log::debug!("Render view"); el::div((map_action(counter_view(model.count), update),)) } diff --git a/xilem_web/web_examples/fetch/src/main.rs b/xilem_web/web_examples/fetch/src/main.rs index 6c17ca7a..7e83697f 100644 --- a/xilem_web/web_examples/fetch/src/main.rs +++ b/xilem_web/web_examples/fetch/src/main.rs @@ -13,7 +13,7 @@ use xilem_web::elements::html::*; use xilem_web::interfaces::{ Element, HtmlDivElement, HtmlImageElement, HtmlInputElement, HtmlLabelElement, }; -use xilem_web::{document_body, App}; +use xilem_web::{App, document_body}; const TOO_MANY_CATS: usize = 8; @@ -101,7 +101,7 @@ where .unchecked_into::() } -fn app_logic(state: &mut AppState) -> impl HtmlDivElement { +fn app_logic(state: &mut AppState) -> impl HtmlDivElement + use<> { div(( cat_fetch_controls(state), fork( @@ -137,7 +137,7 @@ fn app_logic(state: &mut AppState) -> impl HtmlDivElement { )) } -fn cat_images_and_fetching_indicator(state: &AppState) -> impl HtmlDivElement { +fn cat_images_and_fetching_indicator(state: &AppState) -> impl HtmlDivElement + use<> { let cat_images = state .cats .iter() @@ -163,7 +163,7 @@ fn cat_images_and_fetching_indicator(state: &AppState) -> impl HtmlDivElement impl Element { +fn cat_fetch_controls(state: &AppState) -> impl Element + use<> { fieldset(( legend("Cat fetch controls"), table(( diff --git a/xilem_web/web_examples/mathml_svg/src/main.rs b/xilem_web/web_examples/mathml_svg/src/main.rs index 84d48b4b..03e11339 100644 --- a/xilem_web/web_examples/mathml_svg/src/main.rs +++ b/xilem_web/web_examples/mathml_svg/src/main.rs @@ -9,7 +9,7 @@ use wasm_bindgen::{JsCast, UnwrapThrowExt}; use xilem_web::elements::{html, mathml as ml, svg}; use xilem_web::interfaces::*; use xilem_web::modifiers::style as s; -use xilem_web::{document_body, App}; +use xilem_web::{App, document_body}; struct Triangle { a: u32, diff --git a/xilem_web/web_examples/raw_dom_access/src/main.rs b/xilem_web/web_examples/raw_dom_access/src/main.rs index 18257a3a..9df27c41 100644 --- a/xilem_web/web_examples/raw_dom_access/src/main.rs +++ b/xilem_web/web_examples/raw_dom_access/src/main.rs @@ -16,7 +16,7 @@ use std::rc::Rc; use xilem_web::core::one_of::Either; use xilem_web::elements::html; use xilem_web::interfaces::Element; -use xilem_web::{document_body, App, DomView}; +use xilem_web::{App, DomView, document_body}; #[derive(Default)] struct AppState { @@ -24,7 +24,7 @@ struct AppState { show_input: bool, } -fn app_logic(app_state: &mut AppState) -> impl Element { +fn app_logic(app_state: &mut AppState) -> impl Element + use<> { html::div(if app_state.show_input { let focus = Rc::clone(&app_state.focus); Either::A(html::div(( diff --git a/xilem_web/web_examples/spawn_tasks/src/main.rs b/xilem_web/web_examples/spawn_tasks/src/main.rs index d53f1b31..975a5d98 100644 --- a/xilem_web/web_examples/spawn_tasks/src/main.rs +++ b/xilem_web/web_examples/spawn_tasks/src/main.rs @@ -6,14 +6,14 @@ #![expect(clippy::shadow_unrelated, reason = "Idiomatic for Xilem users")] -use futures::{select, FutureExt}; +use futures::{FutureExt, select}; use gloo_timers::future::TimeoutFuture; -use xilem_web::concurrent::{task, ShutdownSignal, TaskProxy}; +use xilem_web::concurrent::{ShutdownSignal, TaskProxy, task}; use xilem_web::core::fork; use xilem_web::core::one_of::Either; use xilem_web::elements::html; use xilem_web::interfaces::Element; -use xilem_web::{document_body, App}; +use xilem_web::{App, document_body}; #[derive(Default)] struct AppState { @@ -52,7 +52,7 @@ async fn create_ping_task(proxy: TaskProxy, shutdown_signal: ShutdownSignal) { log::debug!("Stop ping task"); } -fn app_logic(state: &mut AppState) -> impl Element { +fn app_logic(state: &mut AppState) -> impl Element + use<> { let task = task( create_ping_task, |state: &mut AppState, message: Message| match message { diff --git a/xilem_web/web_examples/svgdraw/src/main.rs b/xilem_web/web_examples/svgdraw/src/main.rs index c165e6b3..619e2f12 100644 --- a/xilem_web/web_examples/svgdraw/src/main.rs +++ b/xilem_web/web_examples/svgdraw/src/main.rs @@ -14,7 +14,7 @@ use xilem_web::interfaces::{ use xilem_web::modifiers::style as s; use xilem_web::svg::kurbo::{BezPath, Point, QuadSpline, Shape, Stroke}; use xilem_web::svg::peniko::Color; -use xilem_web::{document_body, input_event_target_value, AnyDomView, App, DomFragment}; +use xilem_web::{AnyDomView, App, DomFragment, document_body, input_event_target_value}; const RAINBOW_COLORS: [Color; 11] = [ Color::from_rgb8(228, 3, 3), // Red @@ -45,7 +45,7 @@ impl SplineLine { } } - fn view(&self) -> impl SvgPathElement { + fn view(&self) -> impl SvgPathElement + use { QuadSpline::new(self.points.clone()) .to_quads() .fold(BezPath::new(), |mut b, q| { @@ -135,7 +135,7 @@ impl Draw { } } - fn view(&mut self) -> impl DomFragment { + fn view(&mut self) -> impl DomFragment + use<> { let x = -self.canvas_position.x; let y = -self.canvas_position.y; let zoom = self.zoom; diff --git a/xilem_web/web_examples/svgtoy/src/main.rs b/xilem_web/web_examples/svgtoy/src/main.rs index b0bb095c..3a4a1d81 100644 --- a/xilem_web/web_examples/svgtoy/src/main.rs +++ b/xilem_web/web_examples/svgtoy/src/main.rs @@ -7,9 +7,9 @@ use xilem_web::elements::svg::{g, svg, text}; use xilem_web::interfaces::*; use xilem_web::modifiers::style as s; use xilem_web::svg::kurbo::{Circle, Line, Rect, Stroke, Vec2}; -use xilem_web::svg::peniko::color::palette; use xilem_web::svg::peniko::Color; -use xilem_web::{document_body, App, DomView, PointerMsg}; +use xilem_web::svg::peniko::color::palette; +use xilem_web::{App, DomView, PointerMsg, document_body}; #[derive(Default)] struct AppState { @@ -51,7 +51,7 @@ impl GrabState { } } -fn app_logic(state: &mut AppState) -> impl DomView { +fn app_logic(state: &mut AppState) -> impl DomView + use<> { let v = (0..10) .map(|i| { Rect::from_origin_size((10.0 * i as f64, 150.0), (8.0, 8.0)) diff --git a/xilem_web/web_examples/todomvc/src/main.rs b/xilem_web/web_examples/todomvc/src/main.rs index 137342cb..2aaaf32a 100644 --- a/xilem_web/web_examples/todomvc/src/main.rs +++ b/xilem_web/web_examples/todomvc/src/main.rs @@ -10,11 +10,11 @@ mod state; use state::{AppState, Filter, Todo}; use wasm_bindgen::JsCast; -use xilem_web::core::{adapt, MessageResult}; +use xilem_web::core::{MessageResult, adapt}; use xilem_web::elements::html as el; use xilem_web::interfaces::*; use xilem_web::modifiers::style as s; -use xilem_web::{get_element_by_id, Action, App, DomView}; +use xilem_web::{Action, App, DomView, get_element_by_id}; // All of these actions arise from within a `Todo`, but we need access to the full state to reduce // them. @@ -27,7 +27,7 @@ enum TodoAction { impl Action for TodoAction {} -fn todo_item(todo: &mut Todo, editing: bool) -> impl Element { +fn todo_item(todo: &mut Todo, editing: bool) -> impl Element + use<> { let checkbox = el::input(()) .class("toggle") .type_("checkbox") @@ -75,7 +75,7 @@ fn todo_item(todo: &mut Todo, editing: bool) -> impl Element { .class(editing.then_some("editing")) } -fn footer_view(state: &mut AppState, should_display: bool) -> impl Element { +fn footer_view(state: &mut AppState, should_display: bool) -> impl Element + use<> { let clear_button = (state.todos.iter().filter(|todo| todo.completed).count() > 0).then(|| { el::button("Clear completed") .class("clear-completed") @@ -126,7 +126,7 @@ fn footer_view(state: &mut AppState, should_display: bool) -> impl Element impl Element { +fn main_view(state: &mut AppState, should_display: bool) -> impl Element + use<> { let editing_id = state.editing_id; let todos: Vec<_> = state .visible_todos() @@ -165,7 +165,7 @@ fn main_view(state: &mut AppState, should_display: bool) -> impl Element impl DomView { +fn app_logic(state: &mut AppState) -> impl DomView + use<> { tracing::debug!("render: {state:?}"); let some_todos = !state.todos.is_empty(); let main = main_view(state, some_todos);