From 066d4319e8498a50689e1340f1e9c049c727e9ca Mon Sep 17 00:00:00 2001 From: Olivier FAURE Date: Mon, 20 Jan 2025 13:19:26 +0000 Subject: [PATCH] Use nightly rustfmt to format imports (#838) --- tree_arena/src/tree_arena_safe.rs | 4 ++-- tree_arena/src/tree_arena_unsafe.rs | 4 ++-- xilem/examples/emoji_picker.rs | 9 ++++---- xilem/src/view/transform.rs | 6 ++--- xilem/src/view/variable_label.rs | 3 +-- xilem/src/view/zstack.rs | 19 +++++++-------- xilem_core/src/views/map_action.rs | 3 ++- xilem_core/src/views/map_state.rs | 3 ++- xilem_core/src/views/memoize.rs | 3 ++- xilem_web/src/after_update.rs | 6 ++--- xilem_web/src/app.rs | 13 ++++++----- xilem_web/src/concurrent/interval.rs | 11 +++++---- xilem_web/src/concurrent/memoized_await.rs | 14 ++++++----- xilem_web/src/concurrent/task.rs | 18 ++++++++------- xilem_web/src/context.rs | 15 +++++------- xilem_web/src/elements.rs | 13 ++++++----- xilem_web/src/events.rs | 14 ++++++----- xilem_web/src/interfaces.rs | 10 ++++---- xilem_web/src/message.rs | 4 +++- xilem_web/src/modifiers/attribute.rs | 12 +++++----- xilem_web/src/modifiers/class.rs | 17 +++++++------- xilem_web/src/modifiers/overwrite.rs | 3 +-- xilem_web/src/modifiers/style.rs | 21 ++++++++--------- xilem_web/src/one_of.rs | 11 ++++----- xilem_web/src/pod.rs | 3 ++- xilem_web/src/pointer.rs | 15 ++++++------ xilem_web/src/props/element.rs | 11 ++++----- xilem_web/src/props/html_input_element.rs | 4 ++-- xilem_web/src/svg/common_attrs.rs | 16 +++++++------ xilem_web/src/svg/kurbo_shape.rs | 9 ++++---- xilem_web/src/templated.rs | 11 +++++---- xilem_web/src/text.rs | 7 +++--- xilem_web/src/vecmap.rs | 5 +++- xilem_web/web_examples/counter/src/main.rs | 9 +++----- .../counter_custom_element/src/main.rs | 9 +++----- xilem_web/web_examples/elm/src/main.rs | 11 ++++----- xilem_web/web_examples/fetch/src/main.rs | 14 +++++------ xilem_web/web_examples/mathml_svg/src/main.rs | 8 +++---- .../web_examples/raw_dom_access/src/main.rs | 10 ++++---- .../web_examples/spawn_tasks/src/main.rs | 15 +++++------- xilem_web/web_examples/svgdraw/src/main.rs | 23 ++++++++----------- xilem_web/web_examples/svgtoy/src/main.rs | 19 ++++++--------- xilem_web/web_examples/todomvc/src/main.rs | 14 ++++------- 43 files changed, 211 insertions(+), 238 deletions(-) diff --git a/tree_arena/src/tree_arena_safe.rs b/tree_arena/src/tree_arena_safe.rs index aaa29c811..2a3d8ed52 100644 --- a/tree_arena/src/tree_arena_safe.rs +++ b/tree_arena/src/tree_arena_safe.rs @@ -11,10 +11,10 @@ //! will use an arena and unsafe code, but should have the exact same exported API as //! this module. -use super::NodeId; - use hashbrown::HashMap; +use crate::NodeId; + #[derive(Debug)] struct TreeNode { id: NodeId, diff --git a/tree_arena/src/tree_arena_unsafe.rs b/tree_arena/src/tree_arena_unsafe.rs index b58d30b0f..532cfcf92 100644 --- a/tree_arena/src/tree_arena_unsafe.rs +++ b/tree_arena/src/tree_arena_unsafe.rs @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 #![allow(unsafe_code, reason = "Purpose is unsafe abstraction")] -use super::NodeId; - use std::cell::UnsafeCell; use hashbrown::HashMap; +use crate::NodeId; + #[derive(Debug)] struct TreeNode { item: T, diff --git a/xilem/examples/emoji_picker.rs b/xilem/examples/emoji_picker.rs index a58e23499..b999e5c9e 100644 --- a/xilem/examples/emoji_picker.rs +++ b/xilem/examples/emoji_picker.rs @@ -6,12 +6,11 @@ #![expect(clippy::shadow_unrelated, reason = "Idiomatic for Xilem users")] use winit::error::EventLoopError; -use xilem::{ - core::map_state, - palette, - view::{button, flex, grid, label, prose, sized_box, Axis, FlexExt, FlexSpacer, GridExt}, - Color, EventLoop, EventLoopBuilder, WidgetView, Xilem, +use xilem::core::map_state; +use xilem::view::{ + button, flex, grid, label, prose, sized_box, Axis, FlexExt, FlexSpacer, GridExt, }; +use xilem::{palette, Color, EventLoop, EventLoopBuilder, WidgetView, Xilem}; fn app_logic(data: &mut EmojiPagination) -> impl WidgetView { flex(( diff --git a/xilem/src/view/transform.rs b/xilem/src/view/transform.rs index 8a2e974eb..6c6006ca4 100644 --- a/xilem/src/view/transform.rs +++ b/xilem/src/view/transform.rs @@ -3,10 +3,8 @@ use std::marker::PhantomData; -use crate::{ - core::{DynMessage, View, ViewMarker}, - Affine, Pod, ViewCtx, WidgetView, -}; +use crate::core::{DynMessage, View, ViewMarker}; +use crate::{Affine, Pod, ViewCtx, WidgetView}; /// A view which transforms the widget created by child. /// diff --git a/xilem/src/view/variable_label.rs b/xilem/src/view/variable_label.rs index 1c8b697ee..5cf76cd57 100644 --- a/xilem/src/view/variable_label.rs +++ b/xilem/src/view/variable_label.rs @@ -7,11 +7,10 @@ use masonry::{widget, TextAlignment}; use vello::peniko::Brush; use xilem_core::ViewPathTracker; +use super::{label, Label}; use crate::core::{DynMessage, Mut, ViewMarker}; use crate::{MessageResult, Pod, View, ViewCtx, ViewId}; -use super::{label, Label}; - /// A view for displaying non-editable text, with a variable [weight](masonry::parley::style::FontWeight). pub fn variable_label(text: impl Into) -> VariableLabel { VariableLabel { diff --git a/xilem/src/view/zstack.rs b/xilem/src/view/zstack.rs index 30b862249..589dce9eb 100644 --- a/xilem/src/view/zstack.rs +++ b/xilem/src/view/zstack.rs @@ -5,19 +5,16 @@ use std::marker::PhantomData; -use crate::{ - core::{ - AppendVec, DynMessage, ElementSplice, Mut, SuperElement, View, ViewElement, ViewMarker, - ViewSequence, - }, - Pod, ViewCtx, WidgetView, -}; -use masonry::{ - widget::{self, Alignment, ChildAlignment, WidgetMut}, - FromDynWidget, Widget, -}; +use masonry::widget::{self, Alignment, ChildAlignment, WidgetMut}; +use masonry::{FromDynWidget, Widget}; use xilem_core::{MessageResult, ViewId}; +use crate::core::{ + AppendVec, DynMessage, ElementSplice, Mut, SuperElement, View, ViewElement, ViewMarker, + ViewSequence, +}; +use crate::{Pod, ViewCtx, WidgetView}; + /// A widget that lays out its children on top of each other. /// The children are laid out back to front. /// diff --git a/xilem_core/src/views/map_action.rs b/xilem_core/src/views/map_action.rs index 534e58190..6ec6e606b 100644 --- a/xilem_core/src/views/map_action.rs +++ b/xilem_core/src/views/map_action.rs @@ -1,7 +1,8 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use core::{fmt::Debug, marker::PhantomData}; +use core::fmt::Debug; +use core::marker::PhantomData; use crate::{Mut, View, ViewId, ViewMarker, ViewPathTracker}; diff --git a/xilem_core/src/views/map_state.rs b/xilem_core/src/views/map_state.rs index 05c0c0673..7472d52ab 100644 --- a/xilem_core/src/views/map_state.rs +++ b/xilem_core/src/views/map_state.rs @@ -1,7 +1,8 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use core::{fmt::Debug, marker::PhantomData}; +use core::fmt::Debug; +use core::marker::PhantomData; use crate::{MessageResult, Mut, View, ViewId, ViewMarker, ViewPathTracker}; diff --git a/xilem_core/src/views/memoize.rs b/xilem_core/src/views/memoize.rs index f0e299a30..44b081ac2 100644 --- a/xilem_core/src/views/memoize.rs +++ b/xilem_core/src/views/memoize.rs @@ -1,8 +1,9 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 +use core::fmt::Debug; +use core::marker::PhantomData; use core::mem::size_of; -use core::{fmt::Debug, marker::PhantomData}; use crate::{MessageResult, Mut, View, ViewId, ViewMarker, ViewPathTracker}; diff --git a/xilem_web/src/after_update.rs b/xilem_web/src/after_update.rs index da76339a3..3695b8afc 100644 --- a/xilem_web/src/after_update.rs +++ b/xilem_web/src/after_update.rs @@ -3,10 +3,8 @@ use std::marker::PhantomData; -use crate::{ - core::{MessageResult, Mut, View, ViewId, ViewMarker}, - DomNode, DomView, DynMessage, ViewCtx, -}; +use crate::core::{MessageResult, Mut, View, ViewId, ViewMarker}; +use crate::{DomNode, DomView, DynMessage, ViewCtx}; /// Invokes the `callback` after the inner `element` [`DomView`] was created. /// See [`after_build`] for more details. diff --git a/xilem_web/src/app.rs b/xilem_web/src/app.rs index 731c0bb42..af6b27766 100644 --- a/xilem_web/src/app.rs +++ b/xilem_web/src/app.rs @@ -1,14 +1,15 @@ // Copyright 2023 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use crate::{ - core::{AppendVec, MessageResult, ViewId}, - elements::DomChildrenSplice, - AnyPod, DomFragment, DynMessage, ViewCtx, -}; -use std::{cell::RefCell, rc::Rc}; +use std::cell::RefCell; +use std::rc::Rc; + use wasm_bindgen::UnwrapThrowExt; +use crate::core::{AppendVec, MessageResult, ViewId}; +use crate::elements::DomChildrenSplice; +use crate::{AnyPod, DomFragment, DynMessage, ViewCtx}; + pub(crate) struct AppMessage { pub id_path: Rc<[ViewId]>, pub body: DynMessage, diff --git a/xilem_web/src/concurrent/interval.rs b/xilem_web/src/concurrent/interval.rs index 6a02c066b..5b71a4321 100644 --- a/xilem_web/src/concurrent/interval.rs +++ b/xilem_web/src/concurrent/interval.rs @@ -1,12 +1,13 @@ // Copyright 2024 the Xilem Authors and the Druid Authors // SPDX-License-Identifier: Apache-2.0 -use crate::{ - core::{MessageResult, Mut, NoElement, View, ViewId, ViewMarker}, - DynMessage, OptionalAction, ViewCtx, -}; use std::marker::PhantomData; -use wasm_bindgen::{closure::Closure, JsCast, UnwrapThrowExt}; + +use wasm_bindgen::closure::Closure; +use wasm_bindgen::{JsCast, UnwrapThrowExt}; + +use crate::core::{MessageResult, Mut, NoElement, View, ViewId, ViewMarker}; +use crate::{DynMessage, OptionalAction, ViewCtx}; /// Start an interval which invokes `callback` every `ms` milliseconds pub struct Interval { diff --git a/xilem_web/src/concurrent/memoized_await.rs b/xilem_web/src/concurrent/memoized_await.rs index dc63a69f5..40a4059ee 100644 --- a/xilem_web/src/concurrent/memoized_await.rs +++ b/xilem_web/src/concurrent/memoized_await.rs @@ -1,14 +1,16 @@ // Copyright 2024 the Xilem Authors and the Druid Authors // SPDX-License-Identifier: Apache-2.0 -use crate::{ - core::{MessageResult, Mut, NoElement, View, ViewId, ViewMarker, ViewPathTracker}, - DynMessage, OptionalAction, ViewCtx, -}; -use std::{future::Future, marker::PhantomData}; -use wasm_bindgen::{closure::Closure, JsCast, UnwrapThrowExt}; +use std::future::Future; +use std::marker::PhantomData; + +use wasm_bindgen::closure::Closure; +use wasm_bindgen::{JsCast, UnwrapThrowExt}; use wasm_bindgen_futures::spawn_local; +use crate::core::{MessageResult, Mut, NoElement, View, ViewId, ViewMarker, ViewPathTracker}; +use crate::{DynMessage, OptionalAction, ViewCtx}; + /// Await a future returned by `init_future` invoked with the argument `data`, `callback` is called with the output of the future. `init_future` will be invoked again, when `data` changes. Use [`memoized_await`] for construction of this [`View`] pub struct MemoizedAwait { init_future: InitFuture, diff --git a/xilem_web/src/concurrent/task.rs b/xilem_web/src/concurrent/task.rs index 2c3b1924c..53f39bc68 100644 --- a/xilem_web/src/concurrent/task.rs +++ b/xilem_web/src/concurrent/task.rs @@ -1,17 +1,19 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use std::{future::Future, marker::PhantomData, rc::Rc}; - -use crate::{ - context::MessageThunk, - core::{MessageResult, Mut, NoElement, View, ViewId, ViewMarker}, - DynMessage, Message, ViewCtx, -}; -use futures::{channel::oneshot, FutureExt}; +use std::future::Future; +use std::marker::PhantomData; +use std::rc::Rc; + +use futures::channel::oneshot; +use futures::FutureExt; use wasm_bindgen::UnwrapThrowExt; use wasm_bindgen_futures::spawn_local; +use crate::context::MessageThunk; +use crate::core::{MessageResult, Mut, NoElement, View, ViewId, ViewMarker}; +use crate::{DynMessage, Message, ViewCtx}; + /// Spawn an async task to update state asynchronously /// /// The `init_future` function is given a [`TaskProxy`] and a [`ShutdownSignal`]. diff --git a/xilem_web/src/context.rs b/xilem_web/src/context.rs index 4f93acdd8..72dc392e3 100644 --- a/xilem_web/src/context.rs +++ b/xilem_web/src/context.rs @@ -1,18 +1,15 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 +use std::any::{Any, TypeId}; +use std::rc::Rc; + use wasm_bindgen_futures::spawn_local; +use crate::app::{AppMessage, AppRunner}; +use crate::core::{ViewId, ViewPathTracker}; use crate::vecmap::VecMap; -use std::any::Any; -use std::any::TypeId; -use std::rc::Rc; - -use crate::{ - app::{AppMessage, AppRunner}, - core::{ViewId, ViewPathTracker}, - Message, -}; +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 ce799b9f7..184037985 100644 --- a/xilem_web/src/elements.rs +++ b/xilem_web/src/elements.rs @@ -3,17 +3,18 @@ //! Basic builder functions to create DOM elements, such as [`html::div`] +use std::any::Any; use std::borrow::Cow; use std::marker::PhantomData; -use std::{any::Any, rc::Rc}; +use std::rc::Rc; + use wasm_bindgen::{JsCast, UnwrapThrowExt}; +use crate::core::{AppendVec, ElementSplice, MessageResult, Mut, View, ViewId, ViewMarker}; +use crate::modifiers::Children; +use crate::vec_splice::VecSplice; use crate::{ - core::{AppendVec, ElementSplice, MessageResult, Mut, View, ViewId, ViewMarker}, - document, - modifiers::Children, - vec_splice::VecSplice, - AnyPod, DomFragment, DomNode, DynMessage, FromWithContext, Pod, ViewCtx, HTML_NS, + document, AnyPod, DomFragment, DomNode, DynMessage, FromWithContext, Pod, ViewCtx, HTML_NS, }; // 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 bd30b158c..5661febd0 100644 --- a/xilem_web/src/events.rs +++ b/xilem_web/src/events.rs @@ -1,14 +1,16 @@ // Copyright 2023 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use crate::{ - core::{MessageResult, Mut, View, ViewId, ViewMarker, ViewPathTracker}, - DomView, DynMessage, OptionalAction, ViewCtx, -}; -use std::{borrow::Cow, marker::PhantomData}; -use wasm_bindgen::{prelude::Closure, throw_str, JsCast, UnwrapThrowExt}; +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 crate::core::{MessageResult, Mut, View, ViewId, ViewMarker, ViewPathTracker}; +use crate::{DomView, DynMessage, OptionalAction, ViewCtx}; + /// Use a distinctive number here, to be able to catch bugs. /// In case the generational-id view path in `View::Message` lead to a wrong view const ON_EVENT_VIEW_ID: ViewId = ViewId::new(0x2357_1113); diff --git a/xilem_web/src/interfaces.rs b/xilem_web/src/interfaces.rs index 528cb16d5..d209f0382 100644 --- a/xilem_web/src/interfaces.rs +++ b/xilem_web/src/interfaces.rs @@ -14,14 +14,12 @@ use std::borrow::Cow; -use crate::{ - events, - modifiers::{Attr, Class, ClassIter, Rotate, Scale, ScaleValue, Style, StyleIter}, - props::{WithElementProps, WithHtmlInputElementProps}, - DomNode, DomView, IntoAttributeValue, OptionalAction, Pointer, PointerMsg, -}; 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}; + macro_rules! event_handler_mixin { ($(($event_ty: ident, $fn_name:ident, $event:expr, $web_sys_event_type:ident),)*) => { $( diff --git a/xilem_web/src/message.rs b/xilem_web/src/message.rs index 75226e720..34cee27c8 100644 --- a/xilem_web/src/message.rs +++ b/xilem_web/src/message.rs @@ -1,7 +1,9 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use std::{any::Any, fmt::Debug, ops::Deref}; +use std::any::Any; +use std::fmt::Debug; +use std::ops::Deref; /// A dynamically typed message for the [`View`] trait. /// diff --git a/xilem_web/src/modifiers/attribute.rs b/xilem_web/src/modifiers/attribute.rs index 564a65292..5c290b938 100644 --- a/xilem_web/src/modifiers/attribute.rs +++ b/xilem_web/src/modifiers/attribute.rs @@ -1,15 +1,15 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use crate::{ - core::{MessageResult, Mut, View, ViewElement, ViewId, ViewMarker}, - modifiers::{Modifier, WithModifier}, - vecmap::VecMap, - AttributeValue, DomView, DynMessage, IntoAttributeValue, ViewCtx, -}; use std::marker::PhantomData; + use wasm_bindgen::{JsCast, UnwrapThrowExt}; +use crate::core::{MessageResult, Mut, View, ViewElement, ViewId, ViewMarker}; +use crate::modifiers::{Modifier, WithModifier}; +use crate::vecmap::VecMap; +use crate::{AttributeValue, DomView, DynMessage, IntoAttributeValue, ViewCtx}; + type CowStr = std::borrow::Cow<'static, str>; #[derive(Debug, PartialEq, Clone)] diff --git a/xilem_web/src/modifiers/class.rs b/xilem_web/src/modifiers/class.rs index c1c99295b..be650ef32 100644 --- a/xilem_web/src/modifiers/class.rs +++ b/xilem_web/src/modifiers/class.rs @@ -1,16 +1,17 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use crate::{ - core::{MessageResult, Mut, View, ViewElement, ViewId, ViewMarker}, - diff::{diff_iters, Diff}, - modifiers::{Modifier, WithModifier}, - vecmap::VecMap, - DomView, DynMessage, ViewCtx, -}; -use std::{fmt::Debug, marker::PhantomData}; +use std::fmt::Debug; +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::modifiers::{Modifier, WithModifier}; +use crate::vecmap::VecMap; +use crate::{DomView, DynMessage, ViewCtx}; + type CowStr = std::borrow::Cow<'static, str>; #[derive(Debug, PartialEq, Clone)] diff --git a/xilem_web/src/modifiers/overwrite.rs b/xilem_web/src/modifiers/overwrite.rs index b64c82100..92a3d40b2 100644 --- a/xilem_web/src/modifiers/overwrite.rs +++ b/xilem_web/src/modifiers/overwrite.rs @@ -242,9 +242,8 @@ macro_rules! overwrite_bool_modifier_view { #[cfg(test)] mod tests { - use crate::PodFlags; - use super::*; + use crate::PodFlags; #[test] fn overwrite_bool_push() { diff --git a/xilem_web/src/modifiers/style.rs b/xilem_web/src/modifiers/style.rs index f458d0794..e5e7ffbb8 100644 --- a/xilem_web/src/modifiers/style.rs +++ b/xilem_web/src/modifiers/style.rs @@ -1,22 +1,19 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use crate::{ - core::{MessageResult, Mut, View, ViewElement, ViewId, ViewMarker}, - diff::{diff_iters, Diff}, - vecmap::VecMap, - DomView, DynMessage, ViewCtx, -}; +use std::collections::{BTreeMap, HashMap}; +use std::fmt::{Debug, Display}; +use std::hash::{BuildHasher, Hash}; +use std::marker::PhantomData; + use peniko::kurbo::Vec2; -use std::{ - collections::{BTreeMap, HashMap}, - fmt::{Debug, Display}, - hash::{BuildHasher, Hash}, - marker::PhantomData, -}; 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::vecmap::VecMap; +use crate::{DomView, DynMessage, ViewCtx}; type CowStr = std::borrow::Cow<'static, str>; diff --git a/xilem_web/src/one_of.rs b/xilem_web/src/one_of.rs index 4708ef413..3a3cc5bdd 100644 --- a/xilem_web/src/one_of.rs +++ b/xilem_web/src/one_of.rs @@ -1,15 +1,12 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use crate::{ - core::{ - one_of::{OneOf, OneOfCtx, PhantomElementCtx}, - Mut, - }, - DomNode, Pod, PodFlags, PodMut, ViewCtx, -}; use wasm_bindgen::UnwrapThrowExt; +use crate::core::one_of::{OneOf, OneOfCtx, PhantomElementCtx}; +use crate::core::Mut; +use crate::{DomNode, Pod, PodFlags, PodMut, ViewCtx}; + impl OneOfCtx, Pod, Pod, Pod, Pod, Pod, Pod, Pod, Pod> for ViewCtx diff --git a/xilem_web/src/pod.rs b/xilem_web/src/pod.rs index e9817c127..8ecc90281 100644 --- a/xilem_web/src/pod.rs +++ b/xilem_web/src/pod.rs @@ -3,9 +3,10 @@ use std::ops::DerefMut as _; +use wasm_bindgen::UnwrapThrowExt; + use crate::core::{AnyElement, SuperElement, ViewElement}; use crate::{AnyNode, DomNode, ViewCtx}; -use wasm_bindgen::UnwrapThrowExt; /// A container, which holds the actual DOM node, and associated props, such as attributes or classes. /// diff --git a/xilem_web/src/pointer.rs b/xilem_web/src/pointer.rs index 506da2b6f..0408a31a1 100644 --- a/xilem_web/src/pointer.rs +++ b/xilem_web/src/pointer.rs @@ -3,16 +3,17 @@ //! Interactivity with pointer events. -use crate::{ - core::{MessageResult, Mut, View, ViewId, ViewMarker, ViewPathTracker}, - interfaces::Element, - DomView, DynMessage, ViewCtx, -}; -use peniko::kurbo::Point; use std::marker::PhantomData; -use wasm_bindgen::{prelude::Closure, throw_str, JsCast, UnwrapThrowExt}; + +use peniko::kurbo::Point; +use wasm_bindgen::prelude::Closure; +use wasm_bindgen::{throw_str, JsCast, UnwrapThrowExt}; use web_sys::PointerEvent; +use crate::core::{MessageResult, Mut, View, ViewId, ViewMarker, ViewPathTracker}; +use crate::interfaces::Element; +use crate::{DomView, DynMessage, ViewCtx}; + /// Use a distinctive number here, to be able to catch bugs. /// In case the generational-id view path in `View::Message` lead to a wrong view const POINTER_VIEW_ID: ViewId = ViewId::new(0x1234_5014); diff --git a/xilem_web/src/props/element.rs b/xilem_web/src/props/element.rs index 0990a59b3..c6b6cc311 100644 --- a/xilem_web/src/props/element.rs +++ b/xilem_web/src/props/element.rs @@ -1,13 +1,10 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use crate::{ - document, - modifiers::{Attributes, Children, Classes, Modifier, Styles}, - AnyPod, Pod, PodFlags, ViewCtx, -}; -use wasm_bindgen::JsCast; -use wasm_bindgen::UnwrapThrowExt; +use wasm_bindgen::{JsCast, UnwrapThrowExt}; + +use crate::modifiers::{Attributes, Children, Classes, Modifier, Styles}; +use crate::{document, AnyPod, Pod, PodFlags, ViewCtx}; // 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 36146cd04..ee9ff1117 100644 --- a/xilem_web/src/props/html_input_element.rs +++ b/xilem_web/src/props/html_input_element.rs @@ -1,11 +1,11 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use crate::modifiers::html_input_element::{Checked, DefaultChecked, Disabled, Multiple, Required}; -use crate::{props, FromWithContext, Pod, PodFlags, ViewCtx}; 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}; /// Props specific to an input element. pub struct HtmlInputElement { diff --git a/xilem_web/src/svg/common_attrs.rs b/xilem_web/src/svg/common_attrs.rs index 887cf5ef9..465364162 100644 --- a/xilem_web/src/svg/common_attrs.rs +++ b/xilem_web/src/svg/common_attrs.rs @@ -1,15 +1,15 @@ // Copyright 2023 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use crate::{ - core::{MessageResult, Mut, View, ViewElement, ViewId, ViewMarker}, - modifiers::{AttributeModifier, Attributes, Modifier, WithModifier}, - DomView, DynMessage, ViewCtx, -}; -use peniko::{kurbo, Brush}; use std::fmt::Write as _; use std::marker::PhantomData; +use peniko::{kurbo, Brush}; + +use crate::core::{MessageResult, Mut, View, ViewElement, ViewId, ViewMarker}; +use crate::modifiers::{AttributeModifier, Attributes, Modifier, WithModifier}; +use crate::{DomView, DynMessage, ViewCtx}; + pub struct Fill { child: V, // This could reasonably be static Cow also, but keep things simple @@ -295,8 +295,10 @@ where #[cfg(test)] mod tests { + use peniko::color::palette; + use peniko::Brush; + use super::brush_to_string; - use peniko::{color::palette, Brush}; #[test] fn color_brush_to_string() { diff --git a/xilem_web/src/svg/kurbo_shape.rs b/xilem_web/src/svg/kurbo_shape.rs index e3a52ab9f..4af8fdc62 100644 --- a/xilem_web/src/svg/kurbo_shape.rs +++ b/xilem_web/src/svg/kurbo_shape.rs @@ -3,13 +3,12 @@ //! Implementation of the View trait for various kurbo shapes. -use crate::{ - core::{MessageResult, Mut, OrphanView, ViewId}, - modifiers::{Attributes, WithModifier}, - DynMessage, FromWithContext, Pod, ViewCtx, SVG_NS, -}; 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}; + fn create_element( name: &str, ctx: &mut ViewCtx, diff --git a/xilem_web/src/templated.rs b/xilem_web/src/templated.rs index 4266f84b0..3dc0065e3 100644 --- a/xilem_web/src/templated.rs +++ b/xilem_web/src/templated.rs @@ -1,13 +1,14 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use crate::{ - core::{MessageResult, Mut, View, ViewId, ViewMarker}, - DomView, DynMessage, PodMut, ViewCtx, -}; -use std::{any::TypeId, rc::Rc}; +use std::any::TypeId; +use std::rc::Rc; + use wasm_bindgen::UnwrapThrowExt; +use crate::core::{MessageResult, Mut, View, ViewId, ViewMarker}; +use crate::{DomView, DynMessage, PodMut, ViewCtx}; + /// This view creates an internally cached deep-clone of the underlying DOM node. When the inner view is created again, this will be done more efficiently. pub struct Templated(Rc); diff --git a/xilem_web/src/text.rs b/xilem_web/src/text.rs index 0e424b552..975e19605 100644 --- a/xilem_web/src/text.rs +++ b/xilem_web/src/text.rs @@ -1,12 +1,11 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use crate::{ - core::{MessageResult, Mut, OrphanView, ViewId}, - DynMessage, Pod, PodFlags, ViewCtx, -}; use wasm_bindgen::JsCast; +use crate::core::{MessageResult, Mut, OrphanView, ViewId}; +use crate::{DynMessage, Pod, PodFlags, ViewCtx}; + // strings -> text nodes macro_rules! impl_string_view { ($ty:ty) => { diff --git a/xilem_web/src/vecmap.rs b/xilem_web/src/vecmap.rs index d42d404fa..f40fc0414 100644 --- a/xilem_web/src/vecmap.rs +++ b/xilem_web/src/vecmap.rs @@ -1,7 +1,10 @@ // Copyright 2023 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -use std::{borrow::Borrow, fmt, ops::Index, vec::Drain}; +use std::borrow::Borrow; +use std::fmt; +use std::ops::Index; +use std::vec::Drain; #[derive(Clone)] /// Basically an ordered `Map` (similar as `BTreeMap`) with a `Vec` as backend for very few elements diff --git a/xilem_web/web_examples/counter/src/main.rs b/xilem_web/web_examples/counter/src/main.rs index 79ff19042..aa1027b98 100644 --- a/xilem_web/web_examples/counter/src/main.rs +++ b/xilem_web/web_examples/counter/src/main.rs @@ -4,12 +4,9 @@ //! A simple counter #![expect(clippy::shadow_unrelated, reason = "Idiomatic for Xilem users")] -use xilem_web::{ - document_body, - elements::html as el, - interfaces::{Element, HtmlButtonElement}, - App, DomFragment, -}; +use xilem_web::elements::html as el; +use xilem_web::interfaces::{Element, HtmlButtonElement}; +use xilem_web::{document_body, App, DomFragment}; #[derive(Default)] struct AppState { 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 7ba4d0b3f..f36df8372 100644 --- a/xilem_web/web_examples/counter_custom_element/src/main.rs +++ b/xilem_web/web_examples/counter_custom_element/src/main.rs @@ -5,12 +5,9 @@ #![expect(clippy::shadow_unrelated, reason = "Idiomatic for Xilem users")] -use xilem_web::{ - document_body, - elements::custom_element, - interfaces::{Element, HtmlElement}, - App, DomView, -}; +use xilem_web::elements::custom_element; +use xilem_web::interfaces::{Element, HtmlElement}; +use xilem_web::{document_body, App, DomView}; #[derive(Default)] struct AppState { diff --git a/xilem_web/web_examples/elm/src/main.rs b/xilem_web/web_examples/elm/src/main.rs index ad81cc32e..9ccc7f00c 100644 --- a/xilem_web/web_examples/elm/src/main.rs +++ b/xilem_web/web_examples/elm/src/main.rs @@ -7,13 +7,10 @@ //! [`map_state`](xilem_web::core::map_state) or //! [`adapt`](xilem_web::core::adapt). -use xilem_web::{ - core::map_action, - document_body, - elements::html as el, - interfaces::{Element, HtmlDivElement}, - Action, App, -}; +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}; #[derive(Debug, Default)] struct Model { diff --git a/xilem_web/web_examples/fetch/src/main.rs b/xilem_web/web_examples/fetch/src/main.rs index d5153702f..37d09ea91 100644 --- a/xilem_web/web_examples/fetch/src/main.rs +++ b/xilem_web/web_examples/fetch/src/main.rs @@ -10,14 +10,14 @@ use gloo_net::http::Request; use serde::{Deserialize, Serialize}; use wasm_bindgen::{JsCast, UnwrapThrowExt}; -use xilem_web::{ - concurrent::memoized_await, - core::{fork, one_of::Either}, - document_body, - elements::html::*, - interfaces::{Element, HtmlDivElement, HtmlImageElement, HtmlInputElement, HtmlLabelElement}, - App, +use xilem_web::concurrent::memoized_await; +use xilem_web::core::fork; +use xilem_web::core::one_of::Either; +use xilem_web::elements::html::*; +use xilem_web::interfaces::{ + Element, HtmlDivElement, HtmlImageElement, HtmlInputElement, HtmlLabelElement, }; +use xilem_web::{document_body, App}; const TOO_MANY_CATS: usize = 8; diff --git a/xilem_web/web_examples/mathml_svg/src/main.rs b/xilem_web/web_examples/mathml_svg/src/main.rs index 4e0921f50..409365aca 100644 --- a/xilem_web/web_examples/mathml_svg/src/main.rs +++ b/xilem_web/web_examples/mathml_svg/src/main.rs @@ -9,10 +9,10 @@ #![expect(clippy::shadow_unrelated, reason = "Idiomatic for Xilem users")] use wasm_bindgen::{JsCast, UnwrapThrowExt}; -use xilem_web::{ - document_body, elements::html, elements::mathml as ml, elements::svg, interfaces::*, - modifiers::style as s, App, -}; +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}; 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 b5b72ae77..18257a3ac 100644 --- a/xilem_web/web_examples/raw_dom_access/src/main.rs +++ b/xilem_web/web_examples/raw_dom_access/src/main.rs @@ -10,11 +10,13 @@ //! after a callback has been performed in //! `after_build`, `after_rebuild` or `before_teardown`. -use std::{cell::Cell, rc::Rc}; +use std::cell::Cell; +use std::rc::Rc; -use xilem_web::{ - core::one_of::Either, document_body, elements::html, interfaces::Element, App, DomView, -}; +use xilem_web::core::one_of::Either; +use xilem_web::elements::html; +use xilem_web::interfaces::Element; +use xilem_web::{document_body, App, DomView}; #[derive(Default)] struct AppState { diff --git a/xilem_web/web_examples/spawn_tasks/src/main.rs b/xilem_web/web_examples/spawn_tasks/src/main.rs index 76e67912f..d53f1b315 100644 --- a/xilem_web/web_examples/spawn_tasks/src/main.rs +++ b/xilem_web/web_examples/spawn_tasks/src/main.rs @@ -8,15 +8,12 @@ use futures::{select, FutureExt}; use gloo_timers::future::TimeoutFuture; -use xilem_web::{ - concurrent::{task, ShutdownSignal, TaskProxy}, - core::fork, - core::one_of::Either, - document_body, - elements::html, - interfaces::Element, - App, -}; +use xilem_web::concurrent::{task, ShutdownSignal, TaskProxy}; +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}; #[derive(Default)] struct AppState { diff --git a/xilem_web/web_examples/svgdraw/src/main.rs b/xilem_web/web_examples/svgdraw/src/main.rs index cd7ae4e33..b6628ecbb 100644 --- a/xilem_web/web_examples/svgdraw/src/main.rs +++ b/xilem_web/web_examples/svgdraw/src/main.rs @@ -4,22 +4,17 @@ //! An example showing how SVG paths can be used for a vector-drawing application use std::rc::Rc; + use wasm_bindgen::UnwrapThrowExt; -use xilem_web::{ - document_body, - elements::{ - html::{div, input, label, span}, - svg::{g, svg}, - }, - input_event_target_value, - interfaces::{Element, HtmlInputElement, SvgGeometryElement, SvgPathElement, SvggElement}, - modifiers::style as s, - svg::{ - kurbo::{BezPath, Point, QuadSpline, Shape, Stroke}, - peniko::Color, - }, - AnyDomView, App, DomFragment, +use xilem_web::elements::html::{div, input, label, span}; +use xilem_web::elements::svg::{g, svg}; +use xilem_web::interfaces::{ + Element, HtmlInputElement, SvgGeometryElement, SvgPathElement, SvggElement, }; +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}; const RAINBOW_COLORS: [Color; 11] = [ Color::from_rgba8(228, 3, 3, 255), // Red diff --git a/xilem_web/web_examples/svgtoy/src/main.rs b/xilem_web/web_examples/svgtoy/src/main.rs index 3d5cd59cc..bc1797118 100644 --- a/xilem_web/web_examples/svgtoy/src/main.rs +++ b/xilem_web/web_examples/svgtoy/src/main.rs @@ -5,18 +5,13 @@ // TODO: `expect` doesn't work here #![allow(clippy::wildcard_imports, reason = "HTML elements are an exception")] -use xilem_web::{ - document_body, - elements::svg::{g, svg, text}, - interfaces::*, - modifiers::style as s, - svg::{ - kurbo::{Circle, Line, Rect, Stroke, Vec2}, - peniko::color::palette, - peniko::Color, - }, - App, DomView, PointerMsg, -}; +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}; #[derive(Default)] struct AppState { diff --git a/xilem_web/web_examples/todomvc/src/main.rs b/xilem_web/web_examples/todomvc/src/main.rs index 09daffb52..77ab84509 100644 --- a/xilem_web/web_examples/todomvc/src/main.rs +++ b/xilem_web/web_examples/todomvc/src/main.rs @@ -11,16 +11,12 @@ mod state; use state::{AppState, Filter, Todo}; - use wasm_bindgen::JsCast; -use xilem_web::{ - core::{adapt, MessageResult}, - elements::html as el, - get_element_by_id, - interfaces::*, - modifiers::style as s, - Action, App, DomView, -}; +use xilem_web::core::{adapt, MessageResult}; +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}; // All of these actions arise from within a `Todo`, but we need access to the full state to reduce // them.