]> git.proxmox.com Git - ui/proxmox-yew-widget-toolkit.git/commitdiff
tree wide: apply auto-appliable clippy fix-ups
authorShannon Sterz <s.sterz@proxmox.com>
Fri, 3 Jan 2025 10:26:25 +0000 (11:26 +0100)
committerShannon Sterz <s.sterz@proxmox.com>
Fri, 3 Jan 2025 10:26:25 +0000 (11:26 +0100)
this mostly includes:

- switching from `Into` to `From` implementations as that also provides
  an `Into` implementation for "free"
- adding `Default` implementations where possible (e.g. if a `new`
  function without parameters exists)
- removing unnecessary reference and dereference operations (e.g. if the
  compiler would do that automatically anyway)
- using more idiomatic syntax (e.g. using `contains` instead of `<` and
  `>=` operators)
- removing closures where they aren't necessary
- removing `format!` macros where `to_string()` would do to improve
  performance
- remove unnecessary convertions and into calls

these should not change the semantics of the exists code itself, so
there are no breaking changes. however, adding `Default` implementations
and such, does add new public APIs for some types.

110 files changed:
src/async_pool.rs
src/dom/dom_visibility_observer.rs
src/gettext_wrapper.rs
src/props/css_styles.rs
src/props/render_function.rs
src/state/language.rs
src/state/loader.rs
src/state/mod.rs
src/state/navigation_container.rs
src/state/selection.rs
src/state/shared_state.rs
src/state/store.rs
src/state/theme.rs
src/state/tree_store/keyed_slab_tree.rs
src/state/tree_store/mod.rs
src/state/tree_store/slab_tree.rs
src/state/tree_store/slab_tree_serde.rs
src/touch/application_bar.rs
src/touch/fab.rs
src/touch/fab_menu.rs
src/touch/gesture_detector.rs
src/touch/material_app.rs
src/touch/navigation_bar.rs
src/touch/navigation_rail.rs
src/touch/page_stack.rs
src/touch/page_view.rs
src/touch/scaffold.rs
src/touch/side_dialog.rs
src/touch/slidable/slidable_action.rs
src/touch/snack_bar.rs
src/touch/snack_bar_manager.rs
src/widget/action_icon.rs
src/widget/button.rs
src/widget/canvas/animate.rs
src/widget/canvas/animate_transform.rs
src/widget/canvas/circle.rs
src/widget/canvas/ellipse.rs
src/widget/canvas/group.rs
src/widget/canvas/hyperlink.rs
src/widget/canvas/line.rs
src/widget/canvas/mod.rs
src/widget/canvas/path.rs
src/widget/canvas/polygon.rs
src/widget/canvas/polyline.rs
src/widget/canvas/rect.rs
src/widget/canvas/reference.rs
src/widget/canvas/text.rs
src/widget/canvas/tspan.rs
src/widget/card.rs
src/widget/catalog_loader.rs
src/widget/column.rs
src/widget/container.rs
src/widget/data_table/cell_render_callback.rs
src/widget/data_table/column.rs
src/widget/data_table/data_table.rs
src/widget/data_table/header_group.rs
src/widget/data_table/header_state.rs
src/widget/data_table/header_widget.rs
src/widget/data_table/resizable_header.rs
src/widget/data_table/row.rs
src/widget/data_table/row_render_callback.rs
src/widget/desktop_app.rs
src/widget/dialog.rs
src/widget/dropdown.rs
src/widget/fa.rs
src/widget/file_button.rs
src/widget/form/checkbox.rs
src/widget/form/combobox.rs
src/widget/form/context.rs
src/widget/form/field.rs
src/widget/form/form.rs
src/widget/form/hidden.rs
src/widget/form/managed_field.rs
src/widget/form/number.rs
src/widget/form/reset_button.rs
src/widget/form/selector.rs
src/widget/form/submit_button.rs
src/widget/form/textarea.rs
src/widget/form/tristate_boolean.rs
src/widget/grid_picker.rs
src/widget/input.rs
src/widget/input_panel.rs
src/widget/language_selector.rs
src/widget/list/list_tile.rs
src/widget/list/mod.rs
src/widget/mask.rs
src/widget/menu/menu_button.rs
src/widget/menu/menu_checkbox.rs
src/widget/menu/menu_item.rs
src/widget/menu/mod.rs
src/widget/meter.rs
src/widget/mini_scroll.rs
src/widget/nav/mod.rs
src/widget/nav/navigation_drawer.rs
src/widget/panel.rs
src/widget/progress.rs
src/widget/row.rs
src/widget/segmented_button.rs
src/widget/selection_view.rs
src/widget/size_observer.rs
src/widget/split_pane.rs
src/widget/tab/tab_bar.rs
src/widget/tab/tab_bar_item.rs
src/widget/tab/tab_panel.rs
src/widget/theme_density_selector.rs
src/widget/theme_loader.rs
src/widget/theme_mode_selector.rs
src/widget/theme_name_selector.rs
src/widget/toolbar.rs
src/widget/visibility_observer.rs

index 798b64c6690866df9e8875c9c94ac73c419bfdde..728722e880a9c3f0fd7af8ae3fe3b3b0676a5da9 100644 (file)
@@ -24,6 +24,12 @@ struct AsyncPoolInner {
     abort_handles: Rc<RefCell<HashMap<usize, AbortHandle>>>,
 }
 
+impl Default for AsyncPool {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl AsyncPool {
     /// Create a new instance.
     pub fn new() -> Self {
index ab4ff7f630033c104337f040847b3be83af59bb7..74cd3efefda01867af52a2b6196999047184c9c3 100644 (file)
@@ -37,7 +37,7 @@ impl DomVisibilityObserver {
 
         let observer =
             IntersectionObserver::new(observer_closure.as_ref().unchecked_ref()).unwrap_throw();
-        observer.observe(&el);
+        observer.observe(el);
 
         Self {
             _observer_closure: observer_closure, // keep it alive
index b23d8fa89d39af569c338441f1dadc1499c169b1..f986458e3a91055c54b4b211fe115db9ae1dfe86 100644 (file)
@@ -117,7 +117,7 @@ fn convert_js_error(js_err: ::wasm_bindgen::JsValue) -> String {
     if let Ok(error) = ::wasm_bindgen::JsCast::dyn_into::<js_sys::Error>(js_err) {
         format!("{}", error.message())
     } else {
-        format!("unknown js error: error is no ERROR object")
+        "unknown js error: error is no ERROR object".to_string()
     }
 }
 
@@ -129,31 +129,28 @@ async fn fetch_catalog(url: &str) -> Result<(), String> {
     init.method("GET");
     init.signal(Some(&abort.signal()));
 
-    let request =
-        web_sys::Request::new_with_str_and_init(url, &init).map_err(|err| convert_js_error(err))?;
+    let request = web_sys::Request::new_with_str_and_init(url, &init).map_err(convert_js_error)?;
 
-    let window = web_sys::window().ok_or_else(|| format!("unable to get window object"))?;
+    let window = web_sys::window().ok_or_else(|| "unable to get window object".to_string())?;
     let promise = window.fetch_with_request(&request);
 
     let js_resp = wasm_bindgen_futures::JsFuture::from(promise)
         .await
-        .map_err(|err| convert_js_error(err))?;
+        .map_err(convert_js_error)?;
 
     let response: web_sys::Response = js_resp.into();
     let status = response.status();
 
-    if !(status >= 200 && status < 300) {
+    if !(200..300).contains(&status) {
         return Err(format!(
             "Catalog download failed -g ot HTTP status {}",
             status
         ));
     }
-    let promise = response
-        .array_buffer()
-        .map_err(|err| convert_js_error(err))?;
+    let promise = response.array_buffer().map_err(convert_js_error)?;
 
     let js_fut = wasm_bindgen_futures::JsFuture::from(promise);
-    let body = js_fut.await.map_err(|err| convert_js_error(err))?;
+    let body = js_fut.await.map_err(convert_js_error)?;
     let body = js_sys::Uint8Array::new(&body).to_vec();
 
     init_i18n_from_blob(body)?;
index 4b2ba1f8b4a1ce4bcd38055641e2881ad0aefc02..702f5ccf79e4ebf20899dc62656da355533733a6 100644 (file)
@@ -19,12 +19,12 @@ impl CssStyles {
     ) {
         let key = key.into();
         #[cfg(debug_assertions)]
-        if key.contains(|x| x == ';' || x == ':') {
+        if key.contains([';', ':']) {
             panic!("invalid character in style key: '{key}'");
         }
         if let Some(value) = value.into_prop_value() {
             #[cfg(debug_assertions)]
-            if value.contains(|x| x == ';' || x == ':') {
+            if value.contains([';', ':']) {
                 panic!("invalid character in style value '{value}' for '{key}'");
             }
             self.styles
index 8785efa77d10e6cda2655ac68ba9a5b1e548ff73..8773c8b3d548a728783aab3be50a4a56c5a06c05 100644 (file)
@@ -111,9 +111,9 @@ impl<T: Display> IntoOptionalTextRenderFn<T> for bool {
 #[derivative(Clone(bound = ""), PartialEq(bound = ""))]
 pub struct BuilderFn<T>(#[derivative(PartialEq(compare_with = "Rc::ptr_eq"))] Rc<dyn Fn() -> T>);
 
-impl<T: Into<Html>> Into<Html> for BuilderFn<T> {
-    fn into(self) -> Html {
-        self.apply().into()
+impl<T: Into<Html>> From<BuilderFn<T>> for Html {
+    fn from(val: BuilderFn<T>) -> Self {
+        val.apply().into()
     }
 }
 
index 198f71411fa96ef58b06d7547f726e56e47d09e0..182dcc944c6f388b6404a3b45494508dbe7cbca0 100644 (file)
@@ -52,15 +52,12 @@ pub fn get_available_languages() -> Vec<LanguageInfo> {
         .cloned()
         .expect("cannot access available languages before they've been set");
 
-    let list = list
-        .into_iter()
+    list.into_iter()
         .map(|mut info| {
             info.translated_text = gettext(&info.english_text);
             info
         })
-        .collect();
-
-    list
+        .collect()
 }
 
 // this `thread_local!` definition should be fine as this crate is essentially WASM only where
index 2462056587a0c644978c5579482742c83e4aae88..1a74c482e2bb334e9bc04f824c7d15911d8e6610 100644 (file)
@@ -65,6 +65,12 @@ impl<T: 'static + DeserializeOwned + Serialize> LoaderState<T> {
 #[derivative(Clone(bound = ""), PartialEq(bound = ""))]
 pub struct Loader<T>(SharedState<LoaderState<T>>);
 
+impl<T: 'static + DeserializeOwned + Serialize> Default for Loader<T> {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl<T: 'static + DeserializeOwned + Serialize> Loader<T> {
     /// Create a new instance.
     pub fn new() -> Self {
index 3e03ff26865188a19f7d9207de8651c70042c367..4cd37a00397657272053135413059fad6424bac6 100644 (file)
@@ -100,7 +100,7 @@ pub fn delete_state(storage: &StorageLocation) {
         StorageLocation::Session(state_id) => (session_storage(), state_id),
     };
     if let Some(store) = store {
-        let _ = store.delete(&*state_id);
+        let _ = store.delete(state_id);
     }
 }
 
@@ -111,7 +111,7 @@ pub fn load_state<T: 'static + DeserializeOwned>(storage: &StorageLocation) -> O
     };
 
     if let Some(store) = store {
-        if let Ok(Some(item_str)) = store.get_item(&*state_id) {
+        if let Ok(Some(item_str)) = store.get_item(state_id) {
             if let Ok(data) = serde_json::from_str(&item_str) {
                 return Some(data);
             }
@@ -127,13 +127,11 @@ pub fn store_state<T: 'static + Serialize>(data: &T, storage: &StorageLocation)
     };
     if let Some(store) = store {
         let item_str = serde_json::to_string(data).unwrap();
-        match store.set_item(&*state_id, &item_str) {
-            Err(err) => log::error!(
-                "store persistent state {} failed: {}",
-                state_id,
+        if let Err(err) = store.set_item(state_id, &item_str) {
+            log::error!(
+                "store persistent state {state_id} failed: {}",
                 crate::convert_js_error(err)
-            ),
-            Ok(_) => {}
+            )
         }
     }
 }
index f0de55be4633607039af1ba44f8954a99afcf005..eced5096e8a580c380e552eeb44fb29599961a0e 100644 (file)
@@ -136,6 +136,12 @@ pub struct NavigationContainer {
     pub children: Vec<VNode>,
 }
 
+impl Default for NavigationContainer {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl NavigationContainer {
     pub fn new() -> Self {
         yew::props!(Self {})
@@ -168,7 +174,7 @@ impl Component for PwtNavigationContainer {
         let parent_context_handle;
         let location_context_handle;
         let nav_ctx;
-        let on_ctx_update = ctx.link().callback(|nav_ctx| Msg::NavCtxUpdate(nav_ctx));
+        let on_ctx_update = ctx.link().callback(Msg::NavCtxUpdate);
         if let Some((parent_nav_ctx, handle)) =
             ctx.link().context::<NavigationContext>(on_ctx_update)
         {
@@ -176,7 +182,7 @@ impl Component for PwtNavigationContainer {
             parent_context_handle = Some(handle);
             location_context_handle = None;
         } else {
-            let on_loc_update = ctx.link().callback(|loc| Msg::LocationUpdate(loc));
+            let on_loc_update = ctx.link().callback(Msg::LocationUpdate);
             if let Some(loc_handle) = ctx.link().add_location_listener(on_loc_update) {
                 nav_ctx = location_to_nav_ctx(&ctx.link().location());
                 parent_context_handle = None;
@@ -223,9 +229,9 @@ impl Component for PwtNavigationContainer {
     }
 }
 
-impl Into<VNode> for NavigationContainer {
-    fn into(self) -> VNode {
-        let comp = VComp::new::<PwtNavigationContainer>(Rc::new(self), None);
+impl From<NavigationContainer> for VNode {
+    fn from(val: NavigationContainer) -> Self {
+        let comp = VComp::new::<PwtNavigationContainer>(Rc::new(val), None);
         VNode::from(comp)
     }
 }
index c1b8e1d6423b827d52301b4acdd942b94e4aac59..c6cd871609c958fdda20bef6dbb7b46727c2b567 100644 (file)
@@ -66,6 +66,12 @@ impl Drop for SelectionObserver {
     }
 }
 
+impl Default for Selection {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Selection {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -93,10 +99,9 @@ impl Selection {
     /// [Selection] object, so each clone can hold a single on_select
     /// callback.
     pub fn on_select(mut self, cb: impl IntoEventCallback<Selection>) -> Self {
-        self.on_select = match cb.into_event_callback() {
-            Some(cb) => Some(Rc::new(self.add_listener(cb))),
-            None => None,
-        };
+        self.on_select = cb
+            .into_event_callback()
+            .map(|cb| Rc::new(self.add_listener(cb)));
         self
     }
 
@@ -216,7 +221,7 @@ pub struct SelectionWriteGuard<'a> {
     initial_version: usize,
 }
 
-impl<'a> Deref for SelectionWriteGuard<'a> {
+impl Deref for SelectionWriteGuard<'_> {
     type Target = SelectionState;
 
     fn deref(&self) -> &Self::Target {
@@ -224,13 +229,13 @@ impl<'a> Deref for SelectionWriteGuard<'a> {
     }
 }
 
-impl<'a> DerefMut for SelectionWriteGuard<'a> {
+impl DerefMut for SelectionWriteGuard<'_> {
     fn deref_mut(&mut self) -> &mut Self::Target {
         &mut self.state
     }
 }
 
-impl<'a> Drop for SelectionWriteGuard<'a> {
+impl Drop for SelectionWriteGuard<'_> {
     fn drop(&mut self) {
         let changed = self.state.version != self.initial_version;
         unsafe {
@@ -247,7 +252,7 @@ pub struct SelectionReadGuard<'a> {
     state: Ref<'a, SelectionState>,
 }
 
-impl<'a> Deref for SelectionReadGuard<'a> {
+impl Deref for SelectionReadGuard<'_> {
     type Target = SelectionState;
 
     fn deref(&self) -> &Self::Target {
@@ -456,15 +461,15 @@ impl SelectionState {
             false => {
                 if let Some(current) = &self.selection {
                     self.selection = data.find_map(move |rec| {
-                        let key = extract_key.apply(&rec);
-                        (&key == current).then(|| key)
+                        let key = extract_key.apply(rec);
+                        (&key == current).then_some(key)
                     });
                 }
             }
             true => {
                 let mut new_map = HashSet::new();
                 for rec in data {
-                    let key = extract_key.apply(&rec);
+                    let key = extract_key.apply(rec);
                     if self.contains(&key) {
                         new_map.insert(key);
                     }
index f0e7ac9da64cc022d4b8a008d6c43ca5efc1bb99..e96e9fadeaf71698984a1f4bb3955ce369d5ca8c 100644 (file)
@@ -88,10 +88,9 @@ impl<T> SharedState<T> {
     }
 
     pub fn set_on_change(&mut self, cb: impl IntoEventCallback<SharedState<T>>) {
-        self.on_change = match cb.into_event_callback() {
-            Some(cb) => Some(Rc::new(self.add_listener(cb))),
-            None => None,
-        };
+        self.on_change = cb
+            .into_event_callback()
+            .map(|cb| Rc::new(self.add_listener(cb)));
     }
 
     /// Method to add an shared state observer.
@@ -155,7 +154,7 @@ pub struct SharedStateWriteGuard<'a, T> {
                       //initial_version: usize,
 }
 
-impl<'a, T> Deref for SharedStateWriteGuard<'a, T> {
+impl<T> Deref for SharedStateWriteGuard<'_, T> {
     type Target = SharedStateInner<T>;
 
     fn deref(&self) -> &Self::Target {
@@ -163,13 +162,13 @@ impl<'a, T> Deref for SharedStateWriteGuard<'a, T> {
     }
 }
 
-impl<'a, T> DerefMut for SharedStateWriteGuard<'a, T> {
+impl<T> DerefMut for SharedStateWriteGuard<'_, T> {
     fn deref_mut(&mut self) -> &mut Self::Target {
         &mut self.borrowed_state
     }
 }
 
-impl<'a, T> Drop for SharedStateWriteGuard<'a, T> {
+impl<T> Drop for SharedStateWriteGuard<'_, T> {
     fn drop(&mut self) {
         //let changed = self.state.version != self.initial_version;
         let changed = true; // TODO: impl change detection?
@@ -187,7 +186,7 @@ pub struct SharedStateReadGuard<'a, T> {
     borrowed_state: Ref<'a, SharedStateInner<T>>,
 }
 
-impl<'a, T> Deref for SharedStateReadGuard<'a, T> {
+impl<T> Deref for SharedStateReadGuard<'_, T> {
     type Target = SharedStateInner<T>;
 
     fn deref(&self) -> &Self::Target {
index f13458eeef667c73739f29b546132971e0ea49ff..7e6d64280e5f534b4006a19794d46e43f1575b47 100644 (file)
@@ -65,6 +65,12 @@ impl<T: 'static> Drop for StoreObserver<T> {
     }
 }
 
+impl<T: ExtractPrimaryKey + 'static> Default for Store<T> {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl<T: ExtractPrimaryKey + 'static> Store<T> {
     /// Creates a new instance for types implementing [ExtractPrimaryKey].
     ///
@@ -95,10 +101,9 @@ impl<T: 'static> Store<T> {
     /// [Store] object, so each clone can hold a single on_select
     /// callback.
     pub fn on_change(mut self, cb: impl IntoEventCallback<()>) -> Self {
-        self.on_change = match cb.into_event_callback() {
-            Some(cb) => Some(Rc::new(self.add_listener(cb))),
-            None => None,
-        };
+        self.on_change = cb
+            .into_event_callback()
+            .map(|cb| Rc::new(self.add_listener(cb)));
         self
     }
 
@@ -236,13 +241,13 @@ impl<T> Deref for StoreWriteGuard<'_, T> {
     }
 }
 
-impl<'a, T> DerefMut for StoreWriteGuard<'a, T> {
+impl<T> DerefMut for StoreWriteGuard<'_, T> {
     fn deref_mut(&mut self) -> &mut Self::Target {
         &mut self.state
     }
 }
 
-impl<'a, T: 'static> Drop for StoreWriteGuard<'a, T> {
+impl<T: 'static> Drop for StoreWriteGuard<'_, T> {
     fn drop(&mut self) {
         if self.update {
             self.version += 1;
@@ -270,7 +275,7 @@ pub struct StoreNodeRef<'a, T> {
     node_id: usize,
 }
 
-impl<'a, T: 'static> DataNode<T> for StoreNodeRef<'a, T> {
+impl<T: 'static> DataNode<T> for StoreNodeRef<'_, T> {
     fn record(&self) -> DataNodeDerefGuard<T> {
         let data = &self.state.data[self.node_id];
         let guard: Box<dyn Deref<Target = T>> = Box::new(data);
index a50ad10feecaf4cde032e7757289dab16bb52d85..d88737ad3bd48d349f85faca0edfc1f063ebab55 100644 (file)
@@ -100,7 +100,7 @@ pub fn get_available_themes() -> &'static [&'static str] {
 
 fn get_default_theme_name() -> String {
     get_available_themes()
-        .get(0)
+        .first()
         .unwrap_or(&"Material")
         .to_string()
 }
@@ -123,7 +123,7 @@ impl Default for Theme {
         Self {
             mode: ThemeMode::default(),
             density: ThemeDensity::Preset, // use default from css
-            name: String::from(get_default_theme_name()),
+            name: get_default_theme_name(),
         }
     }
 }
@@ -180,7 +180,7 @@ impl Theme {
         let name = theme.name.to_lowercase();
         let themes = get_available_themes();
 
-        if themes.iter().find(|t| t.to_lowercase() == name).is_some() {
+        if themes.iter().any(|t| t.to_lowercase() == name) {
             return theme;
         }
 
index b1c2cc31c20ab556fa8f7cffb573f9dc20972e20..219a5362a489de1b7eed1a98565130ce84c28a47 100644 (file)
@@ -57,14 +57,14 @@ impl<'a, T> KeyedSlabTreeNodeMut<'a, T> {
     }
 }
 
-impl<'a, T> KeyedSlabTreeNodeMut<'a, T> {
+impl<T> KeyedSlabTreeNodeMut<'_, T> {
     impl_slab_node_ref!(KeyedSlabTreeNodeRef<T>);
     impl_slab_node_mut!(KeyedSlabTreeNodeMut<T>, KeyedSlabTree<T>);
 
     /// Iterate over children.
     pub fn children(&self) -> KeyedSlabTreeChildren<T> {
         let entry = self.tree.get(self.node_id).unwrap();
-        let pos = entry.children.is_some().then(|| 0);
+        let pos = entry.children.is_some().then_some(0);
         KeyedSlabTreeChildren {
             node_id: self.node_id,
             tree: self.tree,
@@ -75,7 +75,7 @@ impl<'a, T> KeyedSlabTreeNodeMut<'a, T> {
     /// Iterate over children (mutable).
     pub fn children_mut(&mut self) -> KeyedSlabTreeChildrenMut<T> {
         let entry = self.tree.get(self.node_id).unwrap();
-        let pos = entry.children.is_some().then(|| 0);
+        let pos = entry.children.is_some().then_some(0);
         KeyedSlabTreeChildrenMut {
             node_id: self.node_id,
             tree: self.tree,
@@ -161,13 +161,13 @@ impl<'a, T> KeyedSlabTreeNodeMut<'a, T> {
     }
 }
 
-impl<'a, T> KeyedSlabTreeNodeRef<'a, T> {
+impl<T> KeyedSlabTreeNodeRef<'_, T> {
     impl_slab_node_ref!(KeyedSlabTreeNodeRef<T>);
 
     /// Iterate over children.
     pub fn children(&self) -> KeyedSlabTreeChildren<T> {
         let entry = self.tree.get(self.node_id).unwrap();
-        let pos = entry.children.is_some().then(|| 0);
+        let pos = entry.children.is_some().then_some(0);
         KeyedSlabTreeChildren {
             node_id: self.node_id,
             tree: self.tree,
@@ -216,6 +216,12 @@ impl<T> From<KeyedSlabTree<T>> for SlabTree<T> {
     }
 }
 
+impl<T: ExtractPrimaryKey> Default for KeyedSlabTree<T> {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl<T: ExtractPrimaryKey> KeyedSlabTree<T> {
     pub fn new() -> Self {
         let extract_key = ExtractKeyFn::new(|data: &T| data.extract_key());
index 0206ba0d34b31365a01db5f58807dacb39f1547f..e95a77f41eb5fc34d95ea2f9591cb993f7afebe8 100644 (file)
@@ -76,6 +76,12 @@ pub struct TreeStore<T: 'static> {
     inner: Rc<RefCell<KeyedSlabTree<T>>>,
 }
 
+impl<T: ExtractPrimaryKey + 'static> Default for TreeStore<T> {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl<T: ExtractPrimaryKey + 'static> TreeStore<T> {
     /// Creates a new instance for types implementing [ExtractPrimaryKey].
     ///
@@ -111,10 +117,9 @@ impl<T: 'static> TreeStore<T> {
     /// [TreeStore] object, so each clone can hold a single on_select
     /// callback.
     pub fn on_change(mut self, cb: impl IntoEventCallback<()>) -> Self {
-        self.on_change = match cb.into_event_callback() {
-            Some(cb) => Some(Rc::new(self.add_listener(cb))),
-            None => None,
-        };
+        self.on_change = cb
+            .into_event_callback()
+            .map(|cb| Rc::new(self.add_listener(cb)));
         self
     }
 
@@ -319,13 +324,13 @@ impl<T> Deref for TreeStoreWriteGuard<'_, T> {
     }
 }
 
-impl<'a, T> DerefMut for TreeStoreWriteGuard<'a, T> {
+impl<T> DerefMut for TreeStoreWriteGuard<'_, T> {
     fn deref_mut(&mut self) -> &mut Self::Target {
         &mut self.tree
     }
 }
 
-impl<'a, T> Drop for TreeStoreWriteGuard<'a, T> {
+impl<T> Drop for TreeStoreWriteGuard<'_, T> {
     fn drop(&mut self) {
         if self.tree.version() != self.initial_version {
             self.tree.notify_listeners();
@@ -339,7 +344,7 @@ pub struct KeyedSlabTreeBorrowRef<'a, T: 'static> {
     tree: Ref<'a, KeyedSlabTree<T>>,
 }
 
-impl<'a, T> DataNode<T> for KeyedSlabTreeBorrowRef<'a, T> {
+impl<T> DataNode<T> for KeyedSlabTreeBorrowRef<'_, T> {
     fn record(&self) -> DataNodeDerefGuard<T> {
         let guard = Box::new(RecordGuard {
             node_id: self.node_id,
index 5f69bc11b3173181f72c1df5eb5d7a9921b00c04..2fe0d447ece4e62088c290d1074774e09d6ef5c6 100644 (file)
@@ -296,13 +296,13 @@ macro_rules! impl_slab_node_mut {
     };
 }
 
-impl<'a, T> SlabTreeNodeRef<'a, T> {
+impl<T> SlabTreeNodeRef<'_, T> {
     impl_slab_node_ref!(SlabTreeNodeRef<T>);
 
     /// Iterate over children.
     pub fn children(&self) -> SlabTreeChildren<T> {
         let entry = self.tree.get(self.node_id).unwrap();
-        let pos = entry.children.is_some().then(|| 0);
+        let pos = entry.children.is_some().then_some(0);
         SlabTreeChildren {
             node_id: self.node_id,
             tree: self.tree,
@@ -317,14 +317,14 @@ impl<'a, T> SlabTreeNodeRef<'a, T> {
     }
 }
 
-impl<'a, T> SlabTreeNodeMut<'a, T> {
+impl<T> SlabTreeNodeMut<'_, T> {
     impl_slab_node_ref!(SlabTreeNodeRef<T>);
     impl_slab_node_mut!(SlabTreeNodeMut<T>, SlabTree<T>);
 
     /// Iterate over children.
     pub fn children(&self) -> SlabTreeChildren<T> {
         let entry = self.tree.get(self.node_id).unwrap();
-        let pos = entry.children.is_some().then(|| 0);
+        let pos = entry.children.is_some().then_some(0);
         SlabTreeChildren {
             node_id: self.node_id,
             tree: self.tree,
@@ -335,7 +335,7 @@ impl<'a, T> SlabTreeNodeMut<'a, T> {
     /// Iterate over children (mutable).
     pub fn children_mut(&mut self) -> SlabTreeChildrenMut<T> {
         let entry = self.tree.get(self.node_id).unwrap();
-        let pos = entry.children.is_some().then(|| 0);
+        let pos = entry.children.is_some().then_some(0);
         SlabTreeChildrenMut {
             node_id: self.node_id,
             tree: self.tree,
@@ -350,6 +350,12 @@ impl<'a, T> SlabTreeNodeMut<'a, T> {
     }
 }
 
+impl<T> Default for SlabTree<T> {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl<T> SlabTree<T> {
     pub fn new() -> Self {
         Self {
index 7d6d73954e7d54910e0770ea960918cc64d4e6a8..b9ab2671092f9509afeeda53ef885681046a42d9 100644 (file)
@@ -16,7 +16,7 @@ struct ChildList<'a, T> {
     tree: &'a SlabTree<T>,
 }
 
-impl<'a, T: 'static + Serialize> Serialize for ChildList<'a, T> {
+impl<T: 'static + Serialize> Serialize for ChildList<'_, T> {
     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
     where
         S: Serializer,
@@ -33,7 +33,7 @@ impl<'a, T: 'static + Serialize> Serialize for ChildList<'a, T> {
     }
 }
 
-impl<'a, T: 'static + Serialize> Serialize for SlabTreeNodeRef<'a, T> {
+impl<T: 'static + Serialize> Serialize for SlabTreeNodeRef<'_, T> {
     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
     where
         S: Serializer,
@@ -93,7 +93,7 @@ struct ChildrenVisitor<'a, T> {
     tree: &'a mut SlabTree<T>,
 }
 
-impl<'a, 'de, T: Deserialize<'de>> Visitor<'de> for ChildrenVisitor<'a, T> {
+impl<'de, T: Deserialize<'de>> Visitor<'de> for ChildrenVisitor<'_, T> {
     type Value = Vec<usize>;
 
     fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
@@ -117,7 +117,7 @@ impl<'a, 'de, T: Deserialize<'de>> Visitor<'de> for ChildrenVisitor<'a, T> {
     }
 }
 
-impl<'a, 'de, T: Deserialize<'de>> DeserializeSeed<'de> for ChildrenVisitor<'a, T> {
+impl<'de, T: Deserialize<'de>> DeserializeSeed<'de> for ChildrenVisitor<'_, T> {
     type Value = Vec<usize>;
 
     fn deserialize<D: Deserializer<'de>>(self, deserializer: D) -> Result<Self::Value, D::Error> {
@@ -128,7 +128,7 @@ impl<'a, 'de, T: Deserialize<'de>> DeserializeSeed<'de> for ChildrenVisitor<'a,
 
 static KNOWN_FIELDS: &[&str] = &["record", "expanded", "children"];
 
-impl<'a, 'de, T: Deserialize<'de>> Visitor<'de> for TreeNodeVisitor<'a, T> {
+impl<'de, T: Deserialize<'de>> Visitor<'de> for TreeNodeVisitor<'_, T> {
     type Value = usize;
 
     fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
@@ -227,7 +227,7 @@ impl<'de, T: Deserialize<'de> + ExtractPrimaryKey> Deserialize<'de> for KeyedSla
     }
 }
 
-impl<'a, 'de, T: Deserialize<'de>> DeserializeSeed<'de> for TreeNodeVisitor<'a, T> {
+impl<'de, T: Deserialize<'de>> DeserializeSeed<'de> for TreeNodeVisitor<'_, T> {
     type Value = usize;
 
     fn deserialize<D: Deserializer<'de>>(self, deserializer: D) -> Result<Self::Value, D::Error> {
index 6f46b72c7f60ad807209d280a01226bc70f11f03..637635c930713bb1e2222f50c96bb31bd762cacc 100644 (file)
@@ -38,6 +38,12 @@ pub struct ApplicationBar {
     pub bottom: Option<Html>,
 }
 
+impl Default for ApplicationBar {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl ApplicationBar {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -159,10 +165,10 @@ impl Component for PwtApplicationBar {
     }
 }
 
-impl Into<VNode> for ApplicationBar {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtApplicationBar>(Rc::new(self), key);
+impl From<ApplicationBar> for VNode {
+    fn from(val: ApplicationBar) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtApplicationBar>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index f09de647560b43b3b81abfbdcbeb6aaf55ba980d..1cf06ec8e35c0baad84766187025280f8dd5c745 100644 (file)
@@ -153,10 +153,10 @@ impl Component for PwtFab {
     }
 }
 
-impl Into<VNode> for Fab {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtFab>(Rc::new(self), key);
+impl From<Fab> for VNode {
+    fn from(val: Fab) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtFab>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 5bf1b4117251306c99b0c5d28b991e041371e074..afa48bb4f8b9ff2defe6551cc039a89327714f7a 100644 (file)
@@ -57,6 +57,12 @@ pub struct FabMenu {
     pub children: Vec<Fab>,
 }
 
+impl Default for FabMenu {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl FabMenu {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -186,7 +192,7 @@ impl Component for PwtFabMenu {
                 FabMenuDirection::Left => "pwt-fab-direction-left",
                 FabMenuDirection::Right => "pwt-fab-direction-right",
             })
-            .class(self.show_items.then(|| "active"))
+            .class(self.show_items.then_some("active"))
             .onkeydown({
                 let link = ctx.link().clone();
                 move |event: KeyboardEvent| {
@@ -228,10 +234,10 @@ impl Component for PwtFabMenu {
     }
 }
 
-impl Into<VNode> for FabMenu {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtFabMenu>(Rc::new(self), key);
+impl From<FabMenu> for VNode {
+    fn from(val: FabMenu) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtFabMenu>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 59adaffa474227a817ca5d498d95a77ab4d4db42..2e50e54c26ffb5508cc67cb36fefdd19775c62cc 100644 (file)
@@ -568,10 +568,10 @@ impl Component for PwtGestureDetector {
     }
 }
 
-impl Into<VNode> for GestureDetector {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtGestureDetector>(Rc::new(self), key);
+impl From<GestureDetector> for VNode {
+    fn from(val: GestureDetector) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtGestureDetector>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
@@ -589,6 +589,5 @@ fn compute_distance(x1: i32, y1: i32, x2: i32, y2: i32) -> f64 {
     let dx = (x2 - x1) as f64;
     let dy = (y2 - y1) as f64;
 
-    let radius = (dx * dx + dy * dy).sqrt();
-    radius
+    (dx * dx + dy * dy).sqrt()
 }
index be45738c2417f863901722c98cf22d1e7a7b13b8..d39bc9ab6464b20d3ae70ee24e384c44987a0b10 100644 (file)
@@ -35,6 +35,12 @@ pub struct PageController {
     state: SharedState<Vec<PageControllerMsg>>,
 }
 
+impl Default for PageController {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl PageController {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -304,10 +310,7 @@ impl Component for PwtMaterialApp {
             .clone()
             .unwrap_or(AnyHistory::from(HashHistory::new()));
 
-        let snackbar_controller = props
-            .snackbar_controller
-            .clone()
-            .unwrap_or(SnackBarController::new());
+        let snackbar_controller = props.snackbar_controller.clone().unwrap_or_default();
 
         let page_controller = PageController::new();
 
@@ -392,10 +395,10 @@ impl Component for PwtMaterialApp {
     }
 }
 
-impl Into<VNode> for MaterialApp {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtMaterialApp>(Rc::new(self), key);
+impl From<MaterialApp> for VNode {
+    fn from(val: MaterialApp) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtMaterialApp>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 2637af240ff7ce205481927a80ef287ccced153f..5f0d1e8b9fbe7ecbaba958f93ba2555670b15c5e 100644 (file)
@@ -194,7 +194,7 @@ impl Component for PwtNavigationBar {
                 let key = selection.selected_key();
                 let key = get_active_or_default(props, &key);
 
-                if &self.active == &key {
+                if self.active == key {
                     return false;
                 }
 
@@ -202,7 +202,7 @@ impl Component for PwtNavigationBar {
 
                 if let Some(key) = &self.active {
                     if props.router {
-                        ctx.link().push_relative_route(&key);
+                        ctx.link().push_relative_route(key);
                     }
                 }
 
@@ -217,7 +217,7 @@ impl Component for PwtNavigationBar {
                 log::info!("select {:?}", key);
 
                 let key = get_active_or_default(props, &key);
-                if &self.active == &key {
+                if self.active == key {
                     return false;
                 }
 
@@ -277,18 +277,17 @@ impl Component for PwtNavigationBar {
 
                     let class = classes!(
                         "pwt-navigation-bar-icon-container",
-                        is_active.then(|| "active"),
+                        is_active.then_some("active"),
                     );
                     Some(html! {<div {class}><i class={icon_class}/></div>})
                 }
                 None => None,
             };
-            let label = match &item.label {
-                Some(label) => Some(html! {
+            let label = item.label.as_ref().map(|label| {
+                html! {
                     <div class="pwt-navigation-bar-label">{label}</div>
-                }),
-                None => None,
-            };
+                }
+            });
 
             Container::new()
                 .class("pwt-navigation-bar-item")
@@ -314,10 +313,10 @@ impl Component for PwtNavigationBar {
     }
 }
 
-impl Into<VNode> for NavigationBar {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtNavigationBar>(Rc::new(self), key);
+impl From<NavigationBar> for VNode {
+    fn from(val: NavigationBar) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtNavigationBar>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index ed6c023574503516ccd2b73008f22c1b7230df08..450f71810481da8b86ac83c9544ff646ce98c6f7 100644 (file)
@@ -214,7 +214,7 @@ impl Component for PwtNavigationRail {
                 let key = selection.selected_key();
                 let key = get_active_or_default(props, &key);
 
-                if &self.active == &key {
+                if self.active == key {
                     return false;
                 }
 
@@ -222,7 +222,7 @@ impl Component for PwtNavigationRail {
 
                 if let Some(key) = &self.active {
                     if props.router {
-                        ctx.link().push_relative_route(&key);
+                        ctx.link().push_relative_route(key);
                     }
                 }
 
@@ -237,7 +237,7 @@ impl Component for PwtNavigationRail {
                 log::info!("select {:?}", key);
 
                 let key = get_active_or_default(props, &key);
-                if &self.active == &key {
+                if self.active == key {
                     return false;
                 }
 
@@ -297,18 +297,17 @@ impl Component for PwtNavigationRail {
 
                     let class = classes!(
                         "pwt-navigation-rail-icon-container",
-                        is_active.then(|| "active"),
+                        is_active.then_some("active"),
                     );
                     Some(html! {<div {class}><i class={icon_class}/></div>})
                 }
                 None => None,
             };
-            let label = match &item.label {
-                Some(label) => Some(html! {
+            let label = item.label.as_ref().map(|label| {
+                html! {
                     <div class="pwt-navigation-rail-label">{label}</div>
-                }),
-                None => None,
-            };
+                }
+            });
 
             Container::new()
                 .class("pwt-navigation-rail-item")
@@ -340,10 +339,10 @@ impl Component for PwtNavigationRail {
     }
 }
 
-impl Into<VNode> for NavigationRail {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtNavigationRail>(Rc::new(self), key);
+impl From<NavigationRail> for VNode {
+    fn from(val: NavigationRail) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtNavigationRail>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index d7b674c6f3a912b2d7de3b076b3b035582cc7431..cd66e4b9f4d4696158a4e87441cf4fa78aaecc53 100644 (file)
@@ -18,9 +18,9 @@ pub enum PageAnimationStyle {
     Cover,
 }
 
-impl Into<Classes> for PageAnimationStyle {
-    fn into(self) -> Classes {
-        match self {
+impl From<PageAnimationStyle> for Classes {
+    fn from(val: PageAnimationStyle) -> Self {
+        match val {
             PageAnimationStyle::Push => "pwt-page-animation-push",
             PageAnimationStyle::Fade => "pwt-page-animation-fade",
             PageAnimationStyle::Cover => "pwt-page-animation-cover",
@@ -156,9 +156,9 @@ impl Component for PwtPageStack {
     }
 }
 
-impl Into<VNode> for PageStack {
-    fn into(self) -> VNode {
-        let comp = VComp::new::<PwtPageStack>(Rc::new(self), None);
+impl From<PageStack> for VNode {
+    fn from(val: PageStack) -> Self {
+        let comp = VComp::new::<PwtPageStack>(Rc::new(val), None);
         VNode::from(comp)
     }
 }
index c623bba0eeebc22207c6c91377093ad9eb76c3bb..07953dab5ccd415132f217565e88bd7db6334fb0 100644 (file)
@@ -30,6 +30,12 @@ pub struct PageView {
     pub on_page_change: Option<Callback<usize>>,
 }
 
+impl Default for PageView {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl PageView {
     /// Creates a new instance.
     pub fn new() -> Self {
@@ -148,10 +154,10 @@ impl Component for PwtPageView {
     }
 }
 
-impl Into<VNode> for PageView {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtPageView>(Rc::new(self), key);
+impl From<PageView> for VNode {
+    fn from(val: PageView) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtPageView>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 406c432067cb5526b3c4fca49ec14a47e53bf85c..e16fc62abc86c32ea68844e8e0eb6f381fad364e 100644 (file)
@@ -37,6 +37,12 @@ pub struct Scaffold {
     pub favorite_action_button: Option<VNode>,
 }
 
+impl Default for Scaffold {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Scaffold {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -114,10 +120,10 @@ impl Component for PwtScaffold {
     }
 }
 
-impl Into<VNode> for Scaffold {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtScaffold>(Rc::new(self), key);
+impl From<Scaffold> for VNode {
+    fn from(val: Scaffold) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtScaffold>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 1ed40b35041bed975103b0d3c9f2259b5b92bd52..9d36ca56bf1d97ce36f7ffe06535ae11ddfecb7b 100644 (file)
@@ -27,6 +27,12 @@ pub struct SideDialogController {
     state: SharedState<Vec<SideDialogControllerMsg>>,
 }
 
+impl Default for SideDialogController {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl SideDialogController {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -89,6 +95,12 @@ impl ContainerBuilder for SideDialog {
     }
 }
 
+impl Default for SideDialog {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl SideDialog {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -179,10 +191,7 @@ impl Component for PwtSideDialog {
             .active_element()
             .and_then(|el| el.dyn_into::<HtmlElement>().ok());
 
-        let controller = props
-            .controller
-            .clone()
-            .unwrap_or(SideDialogController::new());
+        let controller = props.controller.clone().unwrap_or_default();
 
         let _controller_observer = controller
             .state
@@ -294,7 +303,7 @@ impl Component for PwtSideDialog {
             Msg::Swipe(event) => {
                 let angle = event.direction; // -180 to + 180
                 let dismiss = match props.direction {
-                    SideDialogLocation::Left => angle > 135.0 || angle < -135.0,
+                    SideDialogLocation::Left => !(-135.0..=135.0).contains(&angle),
                     SideDialogLocation::Right => angle > -45.0 && angle < 45.0,
                     SideDialogLocation::Top => angle > 45.0 && angle < 135.0,
                     SideDialogLocation::Bottom => angle > -135.0 && angle < -45.0,
@@ -420,10 +429,10 @@ impl Component for PwtSideDialog {
     }
 }
 
-impl Into<VNode> for SideDialog {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtSideDialog>(Rc::new(self), key);
+impl From<SideDialog> for VNode {
+    fn from(val: SideDialog) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtSideDialog>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 4daafc8dc1de4d01c39104e7d123cc3e9073cdaf..263ae0e248e66d007e2e551170c4558bf20b3826 100644 (file)
@@ -98,7 +98,7 @@ impl Component for PwtSlidableAction {
     fn view(&self, ctx: &Context<Self>) -> Html {
         let props = ctx.props();
 
-        let icon = props.icon_class.clone().map(|class| Fa::from_class(class));
+        let icon = props.icon_class.clone().map(Fa::from_class);
 
         let onclick = Callback::from({
             let controller = self.controller.clone();
@@ -132,10 +132,10 @@ impl Component for PwtSlidableAction {
     }
 }
 
-impl Into<VNode> for SlidableAction {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtSlidableAction>(Rc::new(self), key);
+impl From<SlidableAction> for VNode {
+    fn from(val: SlidableAction) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtSlidableAction>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 9eed00472fb4ca7c089430a7062d2225eb3159ff..a863cfca474530b04e81d674ec8eb31fcb85442e 100644 (file)
@@ -67,6 +67,12 @@ pub struct SnackBar {
     pub id: Option<AttrValue>,
 }
 
+impl Default for SnackBar {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl SnackBar {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -79,27 +85,27 @@ impl SnackBar {
     }
 }
 
-impl Into<VTag> for SnackBar {
-    fn into(self) -> VTag {
-        let attributes = self.std_props.cumulate_attributes(Some("pwt-snackbar"));
+impl From<SnackBar> for VTag {
+    fn from(val: SnackBar) -> Self {
+        let attributes = val.std_props.cumulate_attributes(Some("pwt-snackbar"));
 
-        let listeners = Listeners::Pending(self.listeners.listeners.into_boxed_slice());
+        let listeners = Listeners::Pending(val.listeners.listeners.into_boxed_slice());
 
         let mut children = Vec::new();
         children.push(
             Container::new()
                 .class("pwt-snackbar-message")
-                .with_child(self.message.clone().unwrap_or(AttrValue::Static("")))
+                .with_child(val.message.clone().unwrap_or(AttrValue::Static("")))
                 .into(),
         );
-        if let Some(action_label) = &self.action_label {
+        if let Some(action_label) = &val.action_label {
             children.push(
                 Button::new(action_label.clone())
                     .class("pwt-button-filled")
                     .class("pwt-snackbar-action")
                     .class("pwt-scheme-inverse-surface")
                     .onclick({
-                        let on_action = self.on_action.clone();
+                        let on_action = val.on_action.clone();
                         move |_| {
                             if let Some(on_action) = &on_action {
                                 on_action.emit(());
@@ -109,10 +115,10 @@ impl Into<VTag> for SnackBar {
                     .into(),
             );
         }
-        if self.show_close_icon {
+        if val.show_close_icon {
             children.push(
                 ActionIcon::new("fa fa-lg fa-close")
-                    .on_activate(self.on_close.clone())
+                    .on_activate(val.on_close.clone())
                     .into(),
             );
         }
@@ -121,8 +127,8 @@ impl Into<VTag> for SnackBar {
 
         VTag::__new_other(
             Cow::Borrowed("div"),
-            self.std_props.node_ref,
-            self.std_props.key,
+            val.std_props.node_ref,
+            val.std_props.key,
             attributes,
             listeners,
             children.into(),
index f79bab368454d3ac8813680aaa15e71fb23bb220..2b0da41083e5c969173b3ed8d118d4985aeaedf1 100644 (file)
@@ -30,6 +30,12 @@ pub struct SnackBarController {
     state: SharedState<Vec<SnackBarControllerMsg>>,
 }
 
+impl Default for SnackBarController {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl SnackBarController {
     pub fn new() -> Self {
         Self {
@@ -95,6 +101,12 @@ pub struct SnackBarManager {
     pub bottom_offset: Option<u32>,
 }
 
+impl Default for SnackBarManager {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl SnackBarManager {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -204,10 +216,7 @@ impl Component for PwtSnackBarManager {
 
     fn create(ctx: &Context<Self>) -> Self {
         let props = ctx.props();
-        let controller = props
-            .controller
-            .clone()
-            .unwrap_or(SnackBarController::new());
+        let controller = props.controller.clone().unwrap_or_default();
 
         let _state_observer = controller
             .state
@@ -316,10 +325,10 @@ impl Component for PwtSnackBarManager {
     }
 }
 
-impl Into<VNode> for SnackBarManager {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtSnackBarManager>(Rc::new(self), key);
+impl From<SnackBarManager> for VNode {
+    fn from(val: SnackBarManager) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtSnackBarManager>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 5c016cbde63c44a46e658b0945407753e1154550..4e2acbf3d8b18cb1f9d9140987673d7252b81a6e 100644 (file)
@@ -141,11 +141,11 @@ impl Component for PwtActionIcon {
 
         Container::from_tag("i")
             .node_ref(props.node_ref.clone())
-            .attribute("tabindex", (!disabled).then(|| tabindex))
+            .attribute("tabindex", (!disabled).then_some(tabindex))
             .attribute("role", "button")
             .attribute("aria-label", props.aria_label.clone())
             .class("pwt-action-icon")
-            .class(props.disabled.then(|| "disabled"))
+            .class(props.disabled.then_some("disabled"))
             .class(props.class.clone())
             .class(props.icon_class.clone())
             .styles(props.style.clone())
@@ -184,10 +184,10 @@ impl Component for PwtActionIcon {
     }
 }
 
-impl Into<VNode> for ActionIcon {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtActionIcon>(Rc::new(self), key);
+impl From<ActionIcon> for VNode {
+    fn from(val: ActionIcon) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtActionIcon>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 50aba5c26dba36e363db2625ead9ef1b9086dd7d..30e6098b34cd302b016492ce811e73ee12968eca 100644 (file)
@@ -13,8 +13,9 @@ use crate::widget::Container;
 
 use pwt_macros::{builder, widget};
 
-#[derive(PartialEq, Clone, Copy)]
+#[derive(PartialEq, Clone, Copy, Default)]
 pub enum ButtonType {
+    #[default]
     Button,
     Submit,
     Reset,
@@ -43,12 +44,6 @@ impl FromStr for ButtonType {
     }
 }
 
-impl Default for ButtonType {
-    fn default() -> Self {
-        ButtonType::Button
-    }
-}
-
 /// Button.
 ///
 /// Buttons can be text only, icons with text, or icons only.
@@ -216,7 +211,7 @@ impl Component for PwtButton {
         }
 
         if let Some(text) = &props.text {
-            children.push((&*text).into());
+            children.push(text.into());
         }
 
         let (x, y, radius) = self.ripple_pos.unwrap_or((0, 0, 0));
@@ -227,7 +222,7 @@ impl Component for PwtButton {
         children.push({
             Container::new()
                 .class("pwt-button-ripple")
-                .class(self.ripple_pos.is_some().then(|| "animate"))
+                .class(self.ripple_pos.is_some().then_some("animate"))
                 .style("--pwt-ripple-x", format!("{x}px"))
                 .style("--pwt-ripple-y", format!("{y}px"))
                 .style("--pwt-ripple-radius", format!("{radius}px"))
@@ -247,10 +242,10 @@ impl Component for PwtButton {
             .children(children)
             .tag("button")
             .class("pwt-button")
-            .class(props.pressed.then(|| "pressed"))
+            .class(props.pressed.then_some("pressed"))
             .attribute("type", Some(props.button_type.to_string()))
-            .attribute("aria-disabled", props.disabled.then(|| "true"))
-            .attribute("autofocus", props.autofocus.then(|| ""))
+            .attribute("aria-disabled", props.disabled.then_some("true"))
+            .attribute("autofocus", props.autofocus.then_some(""))
             .attribute("aria-label", props.aria_label.clone())
             .attribute("tabindex", props.tabindex.map(|i| i.to_string()))
             .onpointerdown(ctx.link().callback(Msg::ShowRippleAnimation))
index 4f2cf025e7bbc528465c5760d23d6866673e40ad..5a18e33c046111cf694a7df769c0344322c2cbe2 100644 (file)
@@ -98,22 +98,22 @@ impl Animate {
     }
 }
 
-impl Into<VTag> for Animate {
-    fn into(self) -> VTag {
+impl From<Animate> for VTag {
+    fn from(val: Animate) -> Self {
         VTag::__new_other(
             "animate".into(),
             NodeRef::default(),
             None,
-            self.attributes,
+            val.attributes,
             Listeners::None,
             VList::new().into(),
         )
     }
 }
 
-impl Into<VNode> for Animate {
-    fn into(self) -> VNode {
-        let vtag: VTag = self.into();
+impl From<Animate> for VNode {
+    fn from(val: Animate) -> Self {
+        let vtag: VTag = val.into();
         VNode::from(vtag)
     }
 }
index ac4191590d07353fc0e192b9efab760407f608cd..a7d07fdc944ed56f86dcdd68d5ee727db9a0bdbb 100644 (file)
@@ -164,22 +164,22 @@ impl AnimateTransform {
     }
 }
 
-impl Into<VTag> for AnimateTransform {
-    fn into(self) -> VTag {
+impl From<AnimateTransform> for VTag {
+    fn from(val: AnimateTransform) -> Self {
         VTag::__new_other(
             "animateTransform".into(),
             NodeRef::default(),
             None,
-            self.attributes,
+            val.attributes,
             Listeners::None,
             VList::new().into(),
         )
     }
 }
 
-impl Into<VNode> for AnimateTransform {
-    fn into(self) -> VNode {
-        let vtag: VTag = self.into();
+impl From<AnimateTransform> for VNode {
+    fn from(val: AnimateTransform) -> Self {
+        let vtag: VTag = val.into();
         VNode::from(vtag)
     }
 }
index c6c2dcac962c58fe8bb9da99e128b782b623b3aa..dae47086f085afd5f5c47ffb65f2cbc3652d429f 100644 (file)
@@ -17,6 +17,12 @@ pub struct Circle {
     children: Option<Vec<VNode>>,
 }
 
+impl Default for Circle {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Circle {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -72,13 +78,13 @@ impl Circle {
     impl_svg_presentation_attributes!();
 }
 
-impl Into<VTag> for Circle {
-    fn into(self) -> VTag {
-        self.std_props.into_vtag(
+impl From<Circle> for VTag {
+    fn from(val: Circle) -> Self {
+        val.std_props.into_vtag(
             Cow::Borrowed("circle"),
             None::<&str>,
-            Some(self.listeners),
-            self.children,
+            Some(val.listeners),
+            val.children,
         )
     }
 }
index 549e9c18affca0b1443c0ac27aae009d65aa05f2..c5eccf267347690de83c8be339a841b9e808ea84 100644 (file)
@@ -17,6 +17,12 @@ pub struct Ellipse {
     children: Option<Vec<VNode>>,
 }
 
+impl Default for Ellipse {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Ellipse {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -61,12 +67,12 @@ impl Ellipse {
     impl_svg_presentation_attributes!();
 }
 
-impl Into<VTag> for Ellipse {
-    fn into(self) -> VTag {
-        self.std_props.into_vtag(
+impl From<Ellipse> for VTag {
+    fn from(val: Ellipse) -> Self {
+        val.std_props.into_vtag(
             Cow::Borrowed("ellipse"),
             None::<&str>,
-            Some(self.listeners),
+            Some(val.listeners),
             None,
         )
     }
index 3e1835613dd0d89c4e044936e06b3dad5b9c281e..a0f530406e1ff9120b6686a40985f0866e75451c 100644 (file)
@@ -14,6 +14,12 @@ use super::SvgLength;
 #[derive(Properties, Clone, PartialEq)]
 pub struct Group {}
 
+impl Default for Group {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Group {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -24,13 +30,13 @@ impl Group {
     impl_svg_presentation_attributes!();
 }
 
-impl Into<VTag> for Group {
-    fn into(self) -> VTag {
-        self.std_props.into_vtag(
+impl From<Group> for VTag {
+    fn from(val: Group) -> Self {
+        val.std_props.into_vtag(
             Cow::Borrowed("g"),
             None::<&str>,
-            Some(self.listeners),
-            Some(self.children),
+            Some(val.listeners),
+            Some(val.children),
         )
     }
 }
index 79ca2a37cb696a50af1d9b85789cae56622404c6..e01d174174eba16cb20a4fdb16b25e10521a170a 100644 (file)
@@ -14,6 +14,12 @@ use crate::props::WidgetBuilder;
 #[derive(Properties, Clone, PartialEq)]
 pub struct Hyperlink {}
 
+impl Default for Hyperlink {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Hyperlink {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -32,13 +38,13 @@ impl Hyperlink {
     }
 }
 
-impl Into<VTag> for Hyperlink {
-    fn into(self) -> VTag {
-        self.std_props.into_vtag(
+impl From<Hyperlink> for VTag {
+    fn from(val: Hyperlink) -> Self {
+        val.std_props.into_vtag(
             Cow::Borrowed("a"),
             None::<&str>,
-            Some(self.listeners),
-            Some(self.children),
+            Some(val.listeners),
+            Some(val.children),
         )
     }
 }
index fa096cd738adaf1c45567c3478cf4d7dae947929..b089cb8f9876c90e66ebb462d4a980196e19f3dd 100644 (file)
@@ -34,13 +34,13 @@ impl Line {
     impl_svg_presentation_attributes!();
 }
 
-impl Into<VTag> for Line {
-    fn into(self) -> VTag {
-        self.std_props.into_vtag(
+impl From<Line> for VTag {
+    fn from(val: Line) -> Self {
+        val.std_props.into_vtag(
             Cow::Borrowed("line"),
             None::<&str>,
-            Some(self.listeners),
-            self.children,
+            Some(val.listeners),
+            val.children,
         )
     }
 }
index 16ebfdd28406df6e4124914242085ac70f2dfebd..80e9cad1d9823041fab0378a34057731056e33ae 100644 (file)
@@ -145,9 +145,9 @@ impl From<i32> for SvgLength {
     }
 }
 
-impl Into<AttrValue> for SvgLength {
-    fn into(self) -> AttrValue {
-        self.to_string().into()
+impl From<SvgLength> for AttrValue {
+    fn from(val: SvgLength) -> Self {
+        val.to_string().into()
     }
 }
 
@@ -162,6 +162,12 @@ impl IntoPropValue<Option<AttrValue>> for SvgLength {
 #[derive(Properties, Clone, PartialEq)]
 pub struct Canvas {}
 
+impl Default for Canvas {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Canvas {
     pub fn new() -> Self {
         yew::props!(Self {})
@@ -186,13 +192,13 @@ impl Canvas {
     }
 }
 
-impl Into<VTag> for Canvas {
-    fn into(self) -> VTag {
-        self.std_props.into_vtag(
+impl From<Canvas> for VTag {
+    fn from(val: Canvas) -> Self {
+        val.std_props.into_vtag(
             Cow::Borrowed("svg"),
             None::<&str>,
-            Some(self.listeners),
-            Some(self.children),
+            Some(val.listeners),
+            Some(val.children),
         )
     }
 }
index ddcd1aecb37a0ee8b83ef96bec351531a865f523..a623384aabec0daccd46feecc4aa367a7f2d6eb3 100644 (file)
@@ -17,6 +17,12 @@ pub struct Path {
     children: Option<Vec<VNode>>,
 }
 
+impl Default for Path {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Path {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -38,13 +44,13 @@ impl Path {
     impl_svg_presentation_attributes!();
 }
 
-impl Into<VTag> for Path {
-    fn into(self) -> VTag {
-        self.std_props.into_vtag(
+impl From<Path> for VTag {
+    fn from(val: Path) -> Self {
+        val.std_props.into_vtag(
             Cow::Borrowed("path"),
             None::<&str>,
-            Some(self.listeners),
-            self.children,
+            Some(val.listeners),
+            val.children,
         )
     }
 }
index b8c1f156ef0907a0f7f6ef9c143140f626a16f4c..67eded71d3b3b41c4b0de954b37777e2a613550e 100644 (file)
@@ -17,6 +17,12 @@ pub struct Polygon {
     children: Option<Vec<VNode>>,
 }
 
+impl Default for Polygon {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Polygon {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -45,13 +51,13 @@ impl Polygon {
     impl_svg_presentation_attributes!();
 }
 
-impl Into<VTag> for Polygon {
-    fn into(self) -> VTag {
-        self.std_props.into_vtag(
+impl From<Polygon> for VTag {
+    fn from(val: Polygon) -> Self {
+        val.std_props.into_vtag(
             Cow::Borrowed("polygon"),
             None::<&str>,
-            Some(self.listeners),
-            self.children,
+            Some(val.listeners),
+            val.children,
         )
     }
 }
index bcf705836a4c5f30b5981efcd2a9d1ca7e5b2ed4..c0c7f38a10057c0ecc3d3b5283af3d12ec81576e 100644 (file)
@@ -17,6 +17,12 @@ pub struct Polyline {
     children: Option<Vec<VNode>>,
 }
 
+impl Default for Polyline {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Polyline {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -45,13 +51,13 @@ impl Polyline {
     impl_svg_presentation_attributes!();
 }
 
-impl Into<VTag> for Polyline {
-    fn into(self) -> VTag {
-        self.std_props.into_vtag(
+impl From<Polyline> for VTag {
+    fn from(val: Polyline) -> Self {
+        val.std_props.into_vtag(
             Cow::Borrowed("polyline"),
             None::<&str>,
-            Some(self.listeners),
-            self.children,
+            Some(val.listeners),
+            val.children,
         )
     }
 }
index 0ca15abff966ea4235fdb1a6831b73fb9ca5a324..0d614ec87256829f52b9ac2d1e3e1dbd18f1303e 100644 (file)
@@ -17,6 +17,12 @@ pub struct Rect {
     children: Option<Vec<VNode>>,
 }
 
+impl Default for Rect {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Rect {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -73,13 +79,13 @@ impl Rect {
     impl_svg_presentation_attributes!();
 }
 
-impl Into<VTag> for Rect {
-    fn into(self) -> VTag {
-        self.std_props.into_vtag(
+impl From<Rect> for VTag {
+    fn from(val: Rect) -> Self {
+        val.std_props.into_vtag(
             Cow::Borrowed("rect"),
             None::<&str>,
-            Some(self.listeners),
-            self.children,
+            Some(val.listeners),
+            val.children,
         )
     }
 }
index 9c46b5ac080a5bca221f7a75804e587f3f8ddd9f..f863a6214d32bb8828afaef37a7f1593b6f84cc4 100644 (file)
@@ -56,13 +56,13 @@ impl Reference {
     impl_svg_presentation_attributes!();
 }
 
-impl Into<VTag> for Reference {
-    fn into(self) -> VTag {
-        self.std_props.into_vtag(
+impl From<Reference> for VTag {
+    fn from(val: Reference) -> Self {
+        val.std_props.into_vtag(
             Cow::Borrowed("use"),
             None::<&str>,
-            Some(self.listeners),
-            self.children,
+            Some(val.listeners),
+            val.children,
         )
     }
 }
index 4732e2a3885dd87e89276d50cdd6a81701943e07..9f08c3990bd39c21cdc8b57b4254677944abcb72 100644 (file)
@@ -84,13 +84,13 @@ impl Text {
     }
 }
 
-impl Into<VTag> for Text {
-    fn into(self) -> VTag {
-        self.std_props.into_vtag(
+impl From<Text> for VTag {
+    fn from(val: Text) -> Self {
+        val.std_props.into_vtag(
             Cow::Borrowed("text"),
             None::<&str>,
-            Some(self.listeners),
-            Some(self.children),
+            Some(val.listeners),
+            Some(val.children),
         )
     }
 }
index b70cac57ea9691b4eb2b98b0a93e4927322ffd2e..f200b5b7cba48f80b3f6f6673a2d89a10c4c9180 100644 (file)
@@ -78,13 +78,13 @@ impl TSpan {
     }
 }
 
-impl Into<VTag> for TSpan {
-    fn into(self) -> VTag {
-        self.std_props.into_vtag(
+impl From<TSpan> for VTag {
+    fn from(val: TSpan) -> Self {
+        val.std_props.into_vtag(
             Cow::Borrowed("tspan"),
             None::<&str>,
-            Some(self.listeners),
-            Some(self.children),
+            Some(val.listeners),
+            Some(val.children),
         )
     }
 }
index da94b90121d2110ebc50614585e6a272195af699..c131f1e68dd4f6b14e624f7a285ec68e809296bd 100644 (file)
@@ -11,6 +11,12 @@ use crate::prelude::*;
 #[derive(Debug, Clone, PartialEq, Properties)]
 pub struct Card {}
 
+impl Default for Card {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Card {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -18,18 +24,18 @@ impl Card {
     }
 }
 
-impl Into<VTag> for Card {
-    fn into(self) -> VTag {
-        let attributes = self.std_props.cumulate_attributes(None::<&str>);
+impl From<Card> for VTag {
+    fn from(val: Card) -> Self {
+        let attributes = val.std_props.cumulate_attributes(None::<&str>);
 
-        let listeners = Listeners::Pending(self.listeners.listeners.into_boxed_slice());
+        let listeners = Listeners::Pending(val.listeners.listeners.into_boxed_slice());
 
-        let children = VList::with_children(self.children, None);
+        let children = VList::with_children(val.children, None);
 
         VTag::__new_other(
             Cow::Borrowed("div"),
-            self.std_props.node_ref,
-            self.std_props.key,
+            val.std_props.node_ref,
+            val.std_props.key,
             attributes,
             listeners,
             children.into(),
index 656b722a5552462bbd9a5d59645d0a499d741a57..214379915fad3df35610e7fd5de3277c5ddf4d4e 100644 (file)
@@ -164,9 +164,9 @@ impl Component for PwtCatalogLoader {
     }
 }
 
-impl Into<VNode> for CatalogLoader {
-    fn into(self) -> VNode {
-        let comp = VComp::new::<PwtCatalogLoader>(Rc::new(self), None);
+impl From<CatalogLoader> for VNode {
+    fn from(val: CatalogLoader) -> Self {
+        let comp = VComp::new::<PwtCatalogLoader>(Rc::new(val), None);
         VNode::from(comp)
     }
 }
index a26fdfe3fc209dd34c0bcc2b430579e679b7ff87..7c7f92d56897b9cb7c17c76b57dca48f5ef394c3 100644 (file)
@@ -14,6 +14,12 @@ use crate::prelude::*;
 #[derive(Debug, Clone, PartialEq, Properties)]
 pub struct Column {}
 
+impl Default for Column {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Column {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -51,18 +57,18 @@ impl Column {
     }
 }
 
-impl Into<VTag> for Column {
-    fn into(self) -> VTag {
-        let attributes = self.std_props.cumulate_attributes(None::<&str>);
+impl From<Column> for VTag {
+    fn from(val: Column) -> Self {
+        let attributes = val.std_props.cumulate_attributes(None::<&str>);
 
-        let listeners = Listeners::Pending(self.listeners.listeners.into_boxed_slice());
+        let listeners = Listeners::Pending(val.listeners.listeners.into_boxed_slice());
 
-        let children = VList::with_children(self.children, None);
+        let children = VList::with_children(val.children, None);
 
         VTag::__new_other(
             Cow::Borrowed("div"),
-            self.std_props.node_ref,
-            self.std_props.key,
+            val.std_props.node_ref,
+            val.std_props.key,
             attributes,
             listeners,
             children.into(),
index 186a82c23325eff53932568b7ec69e30e46d689a..7d6bdc0bbaa80998f1143b0f370f0885d3d659a2 100644 (file)
@@ -46,13 +46,13 @@ impl Container {
     }
 }
 
-impl Into<VTag> for Container {
-    fn into(self) -> VTag {
-        self.std_props.into_vtag(
-            self.tag,
+impl From<Container> for VTag {
+    fn from(val: Container) -> Self {
+        val.std_props.into_vtag(
+            val.tag,
             None::<&str>,
-            Some(self.listeners),
-            Some(self.children),
+            Some(val.listeners),
+            Some(val.children),
         )
     }
 }
index 5251cbf6dbd766ed8d1002a9e2a1706054f09e27..2b38ebc5b37061de99169d3cc561a0c80708f15a 100644 (file)
@@ -36,7 +36,7 @@ pub struct DataTableCellRenderArgs<'a, T> {
     pub config: CellConfiguration,
 }
 
-impl<'a, T> DataTableCellRenderArgs<'a, T> {
+impl<T> DataTableCellRenderArgs<'_, T> {
     /// Return the data node.
     pub fn record(&self) -> &T {
         self.record
index 147fd64f552754e1a61526048804d98947310549..016be990ae778deffe1cd0a6ac52d060622503ff 100644 (file)
@@ -307,7 +307,7 @@ impl<T: 'static> DataTableColumn<T> {
         let get_property_fn = Rc::new(get_property_fn);
         self.sorter({
             let get_property_fn = get_property_fn.clone();
-            move |itema: &T, itemb: &T| get_property_fn(itema).cmp(&get_property_fn(itemb))
+            move |itema: &T, itemb: &T| get_property_fn(itema).cmp(get_property_fn(itemb))
         })
         .render(move |item: &T| html! {{get_property_fn(item)}})
     }
index c13bed8272da259644c443a0ce131868c16a783a..45d4728726ea82f505cea123632025c1742cd4b2 100644 (file)
@@ -599,15 +599,15 @@ impl<S: DataStore> PwtDataTable<S> {
             }
         }
 
-        props.store.filtered_record_pos(&key)
+        props.store.filtered_record_pos(key)
     }
 
     fn set_cursor(&mut self, props: &DataTable<S>, pos: Option<usize>) {
         if let Some(pos) = pos {
-            self.cursor = match props.store.lookup_filtered_record_key(pos) {
-                Some(record_key) => Some(Cursor { pos, record_key }),
-                None => None,
-            }
+            self.cursor = props
+                .store
+                .lookup_filtered_record_key(pos)
+                .map(|record_key| Cursor { pos, record_key })
         } else {
             self.cursor = None;
         }
@@ -783,11 +783,9 @@ impl<S: DataStore> PwtDataTable<S> {
                     }
                 }
                 selection.bulk_select(keys);
-            } else {
-                if let Some(key) = selection.selected_key() {
-                    if props.store.filtered_record_pos(&key).is_none() {
-                        selection.clear();
-                    }
+            } else if let Some(key) = selection.selected_key() {
+                if props.store.filtered_record_pos(&key).is_none() {
+                    selection.clear();
                 }
             }
         }
@@ -815,10 +813,9 @@ impl<S: DataStore> PwtDataTable<S> {
     }
 
     fn focus_cursor(&mut self) {
-        match &self.cursor {
-            Some(Cursor { record_key, .. }) => self.focus_cell(&record_key.clone()),
-            None => return, // nothing to do
-        };
+        if let Some(Cursor { record_key, .. }) = &self.cursor {
+            self.focus_cell(&record_key.clone())
+        }
     }
 
     fn get_row_el(&self, key: &Key) -> Option<web_sys::Element> {
@@ -903,14 +900,14 @@ impl<S: DataStore> PwtDataTable<S> {
             // do not use table tag here to avoid role="table", instead set display type in style"
             .attribute("role", "none")
             .class("pwt-datatable-content")
-            .class(props.hover.then(|| "table-hover"))
-            .class(props.striped.then(|| "table-striped"))
-            .class(props.bordered.then(|| "table-bordered"))
-            .class(props.borderless.then(|| "table-borderless"))
+            .class(props.hover.then_some("table-hover"))
+            .class(props.striped.then_some("table-striped"))
+            .class(props.bordered.then_some("table-bordered"))
+            .class(props.borderless.then_some("table-borderless"))
             .node_ref(self.table_ref.clone())
             .style("display", "table")
-            .style("table-layout", fixed_mode.then(|| "fixed"))
-            .style("width", fixed_mode.then(|| "1px")) // required by table-layout fixed
+            .style("table-layout", fixed_mode.then_some("fixed"))
+            .style("width", fixed_mode.then_some("1px")) // required by table-layout fixed
             .style("position", "relative")
             .style("top", format!("{offset}px"))
             .with_child(first_row);
@@ -950,7 +947,7 @@ impl<S: DataStore> PwtDataTable<S> {
                 cell_config: self.cell_config.clone(),
                 row_render_callback: props.row_render_callback.clone(),
                 selected,
-                active_cell: active.then(|| self.active_column),
+                active_cell: active.then_some(self.active_column),
                 has_focus: active && self.has_focus,
                 is_expanded: item.expanded(),
                 is_leaf: item.is_leaf(),
@@ -1004,9 +1001,7 @@ impl<S: DataStore> PwtDataTable<S> {
             0
         };
 
-        if start > 0 {
-            start -= 1;
-        }
+        start = start.saturating_sub(1);
         if (start & 1) == 1 {
             start -= 1;
         } // make it work with striped rows
@@ -1071,12 +1066,10 @@ impl<S: DataStore + 'static> Component for PwtDataTable<S> {
             .store
             .add_listener(ctx.link().callback(|_| Msg::DataChange));
 
-        let _selection_observer = match &props.selection {
-            Some(selection) => {
-                Some(selection.add_listener(ctx.link().callback(|_| Msg::SelectionChange)))
-            }
-            None => None,
-        };
+        let _selection_observer = props
+            .selection
+            .as_ref()
+            .map(|selection| selection.add_listener(ctx.link().callback(|_| Msg::SelectionChange)));
 
         let mut me = Self {
             _phantom_store: PhantomData::<S>,
@@ -1153,7 +1146,7 @@ impl<S: DataStore + 'static> Component for PwtDataTable<S> {
             Msg::ScrollTo(x, y) => {
                 self.scroll_top = y.max(0) as usize;
                 if let Some(el) = self.header_scroll_ref.cast::<web_sys::Element>() {
-                    el.set_scroll_left(x as i32);
+                    el.set_scroll_left(x);
                 }
                 self.update_scroll_info(props);
                 props.virtual_scroll.unwrap_or(true)
@@ -1615,7 +1608,7 @@ impl<S: DataStore + 'static> Component for PwtDataTable<S> {
 
         let mut active_descendant = None;
         if let Some(Cursor { record_key, .. }) = &self.cursor {
-            active_descendant = Some(self.get_unique_item_id(&record_key));
+            active_descendant = Some(self.get_unique_item_id(record_key));
         }
 
         let column_widths =
@@ -1794,10 +1787,10 @@ impl<S: DataStore + 'static> Component for PwtDataTable<S> {
     }
 }
 
-impl<S: DataStore + 'static> Into<VNode> for DataTable<S> {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtDataTable<S>>(Rc::new(self), key);
+impl<S: DataStore + 'static> From<DataTable<S>> for VNode {
+    fn from(val: DataTable<S>) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtDataTable<S>>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
@@ -1829,7 +1822,7 @@ fn dom_find_focus_pos(el: web_sys::Element, unique_id: &str) -> Option<(Key, Opt
             Some(el) => {
                 if el.tag_name() == "TR" {
                     if let Some(key_str) = el.id().strip_prefix(&unique_row_prefix) {
-                        if key_str.len() == 0 {
+                        if key_str.is_empty() {
                             break;
                         } // stop on errors
                           // try to find out the column_num
index f2b54a22ae1fd3ad0e4f8aa92444d40e0c00a0dd..fc4ec2df1f3ef1589356e7aa6474cb774305ff6c 100644 (file)
@@ -219,7 +219,7 @@ impl<T: 'static> IndexedHeader<T> {
         let cell_count = cells + 1;
         let colspan = span.max(1); // at least one column for the group header
 
-        let indexed_group = IndexedHeaderGroup {
+        IndexedHeaderGroup {
             parent,
             cell_idx,
             start_col,
@@ -229,9 +229,7 @@ impl<T: 'static> IndexedHeader<T> {
             key: group.key.clone(),
             hidden: group.hidden,
             children,
-        };
-
-        indexed_group
+        }
     }
 
     pub fn lookup_cell(headers: &[IndexedHeader<T>], cell_idx: usize) -> Option<&IndexedHeader<T>> {
@@ -290,7 +288,7 @@ impl<T: 'static> IndexedHeader<T> {
 
     pub fn extract_column_list(&self, list: &mut Vec<Rc<IndexedHeaderSingle<T>>>) {
         match self {
-            Self::Single(single) => list.push(Rc::clone(&single)),
+            Self::Single(single) => list.push(Rc::clone(single)),
             Self::Group(group) => group.extract_column_list(list),
         }
     }
index 7e9e2550dfa071b43ab9218b64ef6d95f7191e44..1332a9a750b318a7135f142f009749b6df80ef59 100644 (file)
@@ -128,8 +128,7 @@ impl<T: 'static> HeaderState<T> {
         let visible = group
             .children
             .iter()
-            .find(|cell| !self.get_cell_hidden(cell.cell_idx()))
-            .is_some();
+            .any(|cell| !self.get_cell_hidden(cell.cell_idx()));
         self.cell_state[cell_idx].hidden = !visible;
         self.bubble_up_hidden(group.parent);
     }
index 0f77d9da964b30aec0d780fee625d0cf663acff3..2cf81acf4996febcd5bc4ef2cf731938af9209cb 100644 (file)
@@ -409,7 +409,7 @@ impl<T: 'static> PwtHeaderWidget<T> {
                 // Note: ARIA has no notation for group headers. We need
                 // to hide them to get correct column order.
                 .attribute("role", "none")
-                .attribute("tabindex", props.focusable.then(|| tabindex))
+                .attribute("tabindex", props.focusable.then_some(tabindex))
                 .attribute("id", unique_id)
                 .class("pwt-datatable-group-header-item")
                 .class(props.header_class.clone())
@@ -486,7 +486,7 @@ impl<T: 'static> Component for PwtHeaderWidget<T> {
 
         Self {
             unique_id: get_unique_element_id(),
-            node_ref: props.node_ref.clone().unwrap_or(NodeRef::default()),
+            node_ref: props.node_ref.clone().unwrap_or_default(),
             state,
             cursor: None,
             observed_widths,
@@ -515,11 +515,8 @@ impl<T: 'static> Component for PwtHeaderWidget<T> {
                     .resize((col_num + 1).max(self.observed_widths.len()), None);
                 self.observed_widths[col_num] = Some(width);
 
-                let observed_widths: Vec<f64> = self
-                    .observed_widths
-                    .iter()
-                    .filter_map(|w| w.clone())
-                    .collect();
+                let observed_widths: Vec<f64> =
+                    self.observed_widths.iter().filter_map(|w| *w).collect();
 
                 if self.state.columns().len() == observed_widths.len() {
                     let on_message = props.on_message.clone();
@@ -734,10 +731,10 @@ fn headers_to_menu<T>(
     }
 }
 
-impl<T: 'static> Into<VNode> for HeaderWidget<T> {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtHeaderWidget<T>>(Rc::new(self), key);
+impl<T: 'static> From<HeaderWidget<T>> for VNode {
+    fn from(val: HeaderWidget<T>) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtHeaderWidget<T>>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 5421c0635dbae904d58b3b2e05ea8c0112c6345c..7243dc7c28a7805b08a090ad02fc79c650d3ce94 100644 (file)
@@ -62,6 +62,12 @@ pub struct ResizableHeader {
     pub menu_builder: Option<BuilderFn<Menu>>,
 }
 
+impl Default for ResizableHeader {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl ResizableHeader {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -191,7 +197,7 @@ impl Component for PwtResizableHeader {
         let focus_tracker = FocusTracker::new(ctx.link().callback(Msg::FocusChange));
 
         Self {
-            node_ref: props.node_ref.clone().unwrap_or(NodeRef::default()),
+            node_ref: props.node_ref.clone().unwrap_or_default(),
             rtl: None,
             width: 0.0,
             pointermove_listener: None,
@@ -287,19 +293,18 @@ impl Component for PwtResizableHeader {
             .node_ref(self.node_ref.clone())
             .attribute("role", "none")
             .class("pwt-datatable-header-item")
-            .class(self.has_focus.then(|| "focused"))
+            .class(self.has_focus.then_some("focused"))
             .class(props.class.clone())
             .attribute("id", props.id.clone())
             .onfocusin(self.focus_tracker.get_focus_callback(true))
             .onfocusout(self.focus_tracker.get_focus_callback(false))
             .onkeydown({
                 let link = ctx.link().clone();
-                move |event: KeyboardEvent| match event.key().as_str() {
-                    "ArrowDown" => {
+                move |event: KeyboardEvent| {
+                    if event.key().as_str() == "ArrowDown" {
                         event.stop_propagation();
                         link.send_message(Msg::ShowPicker);
                     }
-                    _ => {}
                 }
             })
             .with_child(
@@ -323,7 +328,7 @@ impl Component for PwtResizableHeader {
                     .autoshow_menu(true)
                     .class("pwt-datatable-header-menu-trigger pwt-button-text")
                     .class(ColorScheme::Primary)
-                    .class((self.has_focus || self.show_picker).then(|| "focused"))
+                    .class((self.has_focus || self.show_picker).then_some("focused"))
                     .icon_class("fa fa-lg fa-caret-down")
                     .ondblclick(|event: MouseEvent| event.stop_propagation())
                     .menu_builder(props.menu_builder.clone())
@@ -375,10 +380,10 @@ impl Component for PwtResizableHeader {
     }
 }
 
-impl Into<VNode> for ResizableHeader {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtResizableHeader>(Rc::new(self), key);
+impl From<ResizableHeader> for VNode {
+    fn from(val: ResizableHeader) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtResizableHeader>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 75549ae1b9aae32111742c9031bf0350048ced65..2770eb95209a0188db90230e3cf64ad136dfcb24 100644 (file)
@@ -73,12 +73,10 @@ impl<T: Clone + PartialEq + 'static> Component for PwtDataTableRow<T> {
 
         let aria_expanded = if props.is_leaf {
             None
+        } else if props.is_expanded {
+            Some("true")
         } else {
-            if props.is_expanded {
-                Some("true")
-            } else {
-                Some("false")
-            }
+            Some("false")
         };
 
         let mut row = Container::from_tag("tr")
@@ -92,8 +90,8 @@ impl<T: Clone + PartialEq + 'static> Component for PwtDataTableRow<T> {
                 if props.selected { "true" } else { "false" },
             )
             .attribute("id", item_id)
-            .class((props.active_cell.is_some() && props.has_focus).then(|| "row-cursor"))
-            .class(props.selected.then(|| "selected")); // fixme: remove
+            .class((props.active_cell.is_some() && props.has_focus).then_some("row-cursor"))
+            .class(props.selected.then_some("selected")); // fixme: remove
 
         if let Some(row_render_callback) = &props.row_render_callback {
             let mut args = DataTableRowRenderArgs {
@@ -155,7 +153,7 @@ impl<T: Clone + PartialEq + 'static> Component for PwtDataTableRow<T> {
 
             let mut td = Container::from_tag("td")
                 .class(args.config.class)
-                .class((cell_active && props.has_focus).then(|| "cell-cursor"))
+                .class((cell_active && props.has_focus).then_some("cell-cursor"))
                 .styles(args.config.style)
                 .style("vertical-align", vertical_align)
                 .style("text-align", text_align)
@@ -189,10 +187,10 @@ impl<T: Clone + PartialEq + 'static> Component for PwtDataTableRow<T> {
     }
 }
 
-impl<T: Clone + PartialEq + 'static> Into<VNode> for DataTableRow<T> {
-    fn into(self) -> VNode {
-        let key = Some(self.record_key.clone());
-        let comp = VComp::new::<PwtDataTableRow<T>>(Rc::new(self), key);
+impl<T: Clone + PartialEq + 'static> From<DataTableRow<T>> for VNode {
+    fn from(val: DataTableRow<T>) -> Self {
+        let key = Some(val.record_key.clone());
+        let comp = VComp::new::<PwtDataTableRow<T>>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index d551900de56609fef59b5fbdc348fdee86395b6a..f9ddaece3c9aeb4d2f4a085c37953ec311488933 100644 (file)
@@ -27,7 +27,7 @@ pub struct DataTableRowRenderArgs<'a, T> {
     pub attributes: IndexMap<AttrValue, AttrValue>,
 }
 
-impl<'a, T> DataTableRowRenderArgs<'a, T> {
+impl<T> DataTableRowRenderArgs<'_, T> {
     /// Return the data node.
     pub fn record(&self) -> &T {
         self.record
index 208e8f32620d9c552a1abc6791c51d176f8b95a2..b87ee67e06758e7a79f35ec8ec66072798b377fc 100644 (file)
@@ -90,10 +90,10 @@ impl Component for PwtDesktopApp {
     }
 }
 
-impl Into<VNode> for DesktopApp {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtDesktopApp>(Rc::new(self), key);
+impl From<DesktopApp> for VNode {
+    fn from(val: DesktopApp) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtDesktopApp>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index a3d0b4689d6d9fdcf7be0c3c331912ceead5b7e7..68fc91b764c138c5e91132c82e776075168bdfa3 100644 (file)
@@ -534,10 +534,10 @@ impl Component for PwtDialog {
     }
 }
 
-impl Into<VNode> for Dialog {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtDialog>(Rc::new(self), key);
+impl From<Dialog> for VNode {
+    fn from(val: Dialog) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtDialog>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index cad563fa038199e8cfaf6e80dee35407bc31cfba..14aa5644febb18204adf4b0065bdd593b7d9dc3a 100644 (file)
@@ -180,7 +180,7 @@ impl Component for PwtDropdown {
             show: false,
             last_show: false,
             pending_change: false,
-            value: ctx.props().value.clone().unwrap_or_else(|| String::new()),
+            value: ctx.props().value.clone().unwrap_or_default(),
             focus_on_field: false,
             change_from_input: false,
             input_ref: NodeRef::default(),
@@ -333,7 +333,7 @@ impl Component for PwtDropdown {
             link: ctx.link().clone(),
         };
 
-        let data_show = self.show.then(|| "true");
+        let data_show = self.show.then_some("true");
 
         let value = props.value.clone().unwrap_or_else(|| self.value.clone());
 
@@ -362,7 +362,7 @@ impl Component for PwtDropdown {
                 .attribute("aria-expanded", if self.show { "true" } else { "false" })
                 .attribute("aria-controls", self.picker_id.clone())
                 .attribute("aria-haspopup", props.popup_type.clone())
-                .attribute("aria-required", props.input_props.required.then(|| ""))
+                .attribute("aria-required", props.input_props.required.then_some(""))
                 .attribute("aria-label", props.input_props.aria_label.clone())
                 .attribute("aria-labelledby", props.input_props.label_id.clone())
                 .attribute("aria-live", "assertive")
@@ -403,7 +403,7 @@ impl Component for PwtDropdown {
             "pwt-dropdown-icon",
             "pwt-pointer",
             if self.show { "fa-angle-up" } else { "fa-angle-down" },
-            disabled.then(|| "disabled"),
+            disabled.then_some("disabled"),
         };
 
         let mut select = Container::new()
@@ -548,10 +548,8 @@ pub fn focus_selected_element(node_ref: &NodeRef) {
             let selected_el = selected_el.dyn_into::<web_sys::HtmlElement>().unwrap();
             if element_is_focusable(&selected_el) {
                 let _ = el.focus();
-            } else {
-                if let Some(focusable_el) = get_first_focusable(selected_el.into()) {
-                    let _ = focusable_el.focus();
-                }
+            } else if let Some(focusable_el) = get_first_focusable(selected_el.into()) {
+                let _ = focusable_el.focus();
             }
         }
     }
index a9ba32b2e883f97a5397bbb0c854a5c0dbd5e01b..844d65bdeaa99e9ac6852f95ba0e90a505dd9c63 100644 (file)
@@ -135,9 +135,9 @@ pub fn pwt_fa(props: &Fa) -> Html {
     }
 }
 
-impl Into<VNode> for Fa {
-    fn into(self) -> VNode {
-        let comp = VComp::new::<PwtFa>(Rc::new(self), None);
+impl From<Fa> for VNode {
+    fn from(val: Fa) -> Self {
+        let comp = VComp::new::<PwtFa>(Rc::new(val), None);
         VNode::from(comp)
     }
 }
index 56f782266633ea0cd7a76783d9316f8ac7bbfd32..8e8d60a676209a2689781b742b74211b826dc6dc 100644 (file)
@@ -180,7 +180,7 @@ impl Component for PwtFileButton {
         }
 
         if let Some(text) = &props.text {
-            children.push((&*text).into());
+            children.push(text.into());
         }
 
         let (x, y, radius) = self.ripple_pos.unwrap_or((0, 0, 0));
@@ -191,7 +191,7 @@ impl Component for PwtFileButton {
         children.push({
             Container::new()
                 .class("pwt-button-ripple")
-                .class(self.ripple_pos.is_some().then(|| "animate"))
+                .class(self.ripple_pos.is_some().then_some("animate"))
                 .style("--pwt-ripple-x", format!("{x}px"))
                 .style("--pwt-ripple-y", format!("{y}px"))
                 .style("--pwt-ripple-radius", format!("{radius}px"))
@@ -206,7 +206,7 @@ impl Component for PwtFileButton {
                 .node_ref(self.input_ref.clone())
                 .attribute("type", "file")
                 .attribute("accept", props.accept.clone())
-                .attribute("multiple", props.multiple.then(|| ""))
+                .attribute("multiple", props.multiple.then_some(""))
                 .class("pwt-d-none")
                 .oncancel(suppress_oncancel)
                 .onchange({
@@ -229,9 +229,9 @@ impl Component for PwtFileButton {
             .children(children)
             .tag("label")
             .class("pwt-button")
-            .class(props.pressed.then(|| "pressed"))
-            .attribute("aria-disabled", props.disabled.then(|| "true"))
-            .attribute("autofocus", props.autofocus.then(|| ""))
+            .class(props.pressed.then_some("pressed"))
+            .attribute("aria-disabled", props.disabled.then_some("true"))
+            .attribute("autofocus", props.autofocus.then_some(""))
             .attribute("aria-label", props.aria_label.clone())
             .attribute("tabindex", props.tabindex.map(|i| i.to_string()))
             .onpointerdown(ctx.link().callback(Msg::ShowRippleAnimation))
index cf4069069432563454f7dc69f14cee37d79c7c20..3cd6a5f1dc76836bc78ce7f8be9f11d115b75061 100644 (file)
@@ -95,6 +95,12 @@ pub struct Checkbox {
     pub box_label: Option<FieldLabel>,
 }
 
+impl Default for Checkbox {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Checkbox {
     /// Creates a new instance.
     pub fn new() -> Self {
index 220bccf6f5214389559a5bc9a4457aff817ecd1e..3a3a4ccbf7c0df3e3187e66ede82ec63ca1e5377 100644 (file)
@@ -83,6 +83,12 @@ pub struct Combobox {
     pub trigger: Vec<(Trigger, bool)>,
 }
 
+impl Default for Combobox {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Combobox {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -206,13 +212,9 @@ impl Component for PwtCombobox {
         let props = ctx.props();
         let link = ctx.link().clone();
 
-        let show_filter = props.show_filter.unwrap_or_else(|| {
-            if self.store.data_len() > 10 {
-                true
-            } else {
-                false
-            }
-        });
+        let show_filter = props
+            .show_filter
+            .unwrap_or_else(|| self.store.data_len() > 10);
 
         let filter = props.filter.clone();
 
index 6bfcf656ce2286842796647b204725cbb45ba4ba..fe4588ba948476e60c00e5556669c141e5edb9f1 100644 (file)
@@ -214,6 +214,12 @@ impl Drop for FieldHandle {
     }
 }
 
+impl Default for FormContext {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl FormContext {
     pub fn new() -> Self {
         Self {
@@ -229,10 +235,9 @@ impl FormContext {
     /// [FormContext] object, so each clone can hold a single on_change
     /// callback.
     pub fn on_change(mut self, cb: impl IntoEventCallback<FormContext>) -> Self {
-        self.on_change = match cb.into_event_callback() {
-            Some(cb) => Some(Rc::new(self.add_listener(cb))),
-            None => None,
-        };
+        self.on_change = cb
+            .into_event_callback()
+            .map(|cb| Rc::new(self.add_listener(cb)));
         self
     }
 
@@ -356,13 +361,13 @@ impl Deref for FormContextWriteGuard<'_> {
     }
 }
 
-impl<'a> DerefMut for FormContextWriteGuard<'a> {
+impl DerefMut for FormContextWriteGuard<'_> {
     fn deref_mut(&mut self) -> &mut Self::Target {
         &mut self.state
     }
 }
 
-impl<'a> Drop for FormContextWriteGuard<'a> {
+impl Drop for FormContextWriteGuard<'_> {
     fn drop(&mut self) {
         let changed = self.state.version != self.initial_version;
         unsafe {
@@ -539,10 +544,8 @@ impl FormContextState {
         name: impl IntoPropValue<AttrValue>,
     ) -> Option<(Value, Result<(), String>)> {
         let name = name.into_prop_value();
-        match self.find_field_slab_id(&name) {
-            Some(key) => Some(self.get_field_data_by_slab_key(key)),
-            None => None,
-        }
+        self.find_field_slab_id(&name)
+            .map(|key| self.get_field_data_by_slab_key(key))
     }
 
     /// Get the field value.
@@ -797,10 +800,7 @@ impl FormContextState {
             };
 
             // Are there radio group fields?
-            let radio_group_key = group
-                .members
-                .iter()
-                .find(|k| self.fields[**k].radio_group == true);
+            let radio_group_key = group.members.iter().find(|k| self.fields[**k].radio_group);
 
             if let Some(radio_group_key) = radio_group_key {
                 // Note: we only call set_value for one radio_group member
@@ -843,14 +843,14 @@ impl FormContextState {
                 .members
                 .iter()
                 .filter(|k| !self.fields[**k].radio_group)
-                .map(|k| *k)
+                .copied()
                 .collect();
 
             let radio_keys: Vec<usize> = group
                 .members
                 .iter()
                 .filter(|k| self.fields[**k].radio_group)
-                .map(|k| *k)
+                .copied()
                 .collect();
 
             if !radio_keys.is_empty() {
@@ -887,7 +887,7 @@ impl FormContextState {
                     match &field.submit_value {
                         None => continue,
                         Some(value) => {
-                            if !submit_empty & value_is_empty(&value) {
+                            if !submit_empty & value_is_empty(value) {
                                 continue;
                             }
                             data[name.deref()] = value.clone();
@@ -907,7 +907,7 @@ impl FormContextState {
                         match &field.submit_value {
                             None => continue,
                             Some(value) => {
-                                if !submit_empty & value_is_empty(&value) {
+                                if !submit_empty & value_is_empty(value) {
                                     continue;
                                 }
                                 list.push(value.clone());
index 33c97d308adbf003c7fb45a2c24b22c0a921c4a4..c93d877a226b3491995aa5c551db4d4bf1192c12 100644 (file)
@@ -24,7 +24,7 @@ pub type PwtField = ManagedFieldMaster<StandardField>;
 /// Valid Input types for a [Field]
 // taken from https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
 // Commented out values would be valid, but don't make sense for the field.
-#[derive(PartialEq, Clone, Copy)]
+#[derive(PartialEq, Clone, Copy, Default)]
 pub enum InputType {
     //Button,
     //Checkbox,
@@ -44,18 +44,13 @@ pub enum InputType {
     Search,
     //Submit,
     Tel,
+    #[default]
     Text,
     Time,
     Url,
     Week,
 }
 
-impl Default for InputType {
-    fn default() -> Self {
-        InputType::Text
-    }
-}
-
 impl Display for InputType {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         f.write_str(match self {
@@ -195,6 +190,12 @@ pub struct Field {
     pub tip: Option<AttrValue>,
 }
 
+impl Default for Field {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Field {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -308,7 +309,7 @@ impl ManagedField for StandardField {
     fn validation_args(props: &Self::Properties) -> Self::ValidateClosure {
         ValidateClosure {
             required: props.input_props.required,
-            input_type: props.input_type.clone(),
+            input_type: props.input_type,
             min: props.min,
             max: props.max,
             validate: props.validate.clone(),
index 9b28daac312d487b4978beab34b5152952b5fe70..68e9183f4faa0b5ba9b0a391caba8197eff08f7f 100644 (file)
@@ -21,6 +21,12 @@ pub struct Form {
     pub form_context: Option<FormContext>,
 }
 
+impl Default for Form {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Form {
     /// Creates a new instance.
     pub fn new() -> Self {
index 075d473dc481eb8f419b9b6653f5429a7d59f15c..47106a7db8c0abff24acaaeb3ec1b280fc58fd6e 100644 (file)
@@ -33,6 +33,12 @@ pub struct Hidden {
     pub on_change: Option<Callback<Value>>,
 }
 
+impl Default for Hidden {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Hidden {
     /// Creates a new instance.
     pub fn new() -> Self {
@@ -48,9 +54,7 @@ impl ManagedField for HiddenField {
     type Message = ();
     type ValidateClosure = ();
 
-    fn validation_args(_props: &Self::Properties) -> Self::ValidateClosure {
-        ()
-    }
+    fn validation_args(_props: &Self::Properties) -> Self::ValidateClosure {}
 
     fn setup(props: &Hidden) -> ManagedFieldState {
         let mut value = Value::Null;
index 4075dbb56426e11348e0024f787393f5f1b6a5a8..0ca7ae0792399c7aa5ac0c82c7e8996c0c09d290 100644 (file)
@@ -67,7 +67,7 @@ impl<'a, MF: ManagedField + Sized> ManagedFieldContext<'a, MF> {
 
     /// Current field state.
     pub fn state(&self) -> &ManagedFieldState {
-        &self.comp_state
+        self.comp_state
     }
 }
 
@@ -525,7 +525,7 @@ impl<MF: ManagedField + 'static> Component for ManagedFieldMaster<MF> {
                     }) as Box<dyn Fn()>
                 });
 
-                if let Some(el) = document.get_element_by_id(&label_id) {
+                if let Some(el) = document.get_element_by_id(label_id) {
                     let _ = el.add_event_listener_with_callback(
                         "click",
                         label_clicked_closure.as_ref().unchecked_ref(),
index 22ca7847cdaebe28687a871ef40bcde62e36a0d3..8d819a750e9db7da8ae2e1a7e9731f4e9f0e0c8a 100644 (file)
@@ -46,15 +46,15 @@ impl NumberTypeInfo for f64 {
         match value {
             Value::Number(n) => match n.as_f64() {
                 Some(n) => Ok(n),
-                None => return Err(Error::msg(tr!("cannot represent number as f64"))),
+                None => Err(Error::msg(tr!("cannot represent number as f64"))),
             },
             Value::String(s) => {
                 // Note: this handles localized number format
-                let number = crate::dom::parse_float(s).map_err(|err| Error::msg(err))?;
+                let number = crate::dom::parse_float(s).map_err(Error::msg)?;
 
-                return Ok(number);
+                Ok(number)
             }
-            _ => return Err(Error::msg(tr!("got wrong data type"))),
+            _ => Err(Error::msg(tr!("got wrong data type"))),
         }
     }
     fn number_to_value(&self) -> Value {
@@ -359,6 +359,12 @@ pub struct Number<T: NumberTypeInfo> {
     pub on_input: Option<Callback<(String, Option<T>)>>,
 }
 
+impl<T: NumberTypeInfo> Default for Number<T> {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl<T: NumberTypeInfo> Number<T> {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -471,7 +477,7 @@ impl<T: NumberTypeInfo> ManagedField for NumberField<T> {
             value = force_value.to_string().into();
         }
 
-        let value: Value = value.clone().into();
+        let value: Value = value.clone();
 
         let default = match props.default {
             Some(default) => T::number_to_value(&default),
@@ -635,7 +641,7 @@ impl<T: NumberTypeInfo> ManagedField for NumberField<T> {
                 move |event: KeyboardEvent| match event.key().as_str() {
                     "ArrowDown" => link.send_message(Msg::Down),
                     "ArrowUp" => link.send_message(Msg::Up),
-                    _ => return,
+                    _ => (),
                 }
             })
             .onwheel({
index 383161a752f3a87cd4e45093e152fbcd232514b4..214fdd3ae26030937cc1d2528af92d32a6915a7c 100644 (file)
@@ -35,6 +35,12 @@ pub struct ResetButton {
     pub class: Classes,
 }
 
+impl Default for ResetButton {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl ResetButton {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -145,9 +151,9 @@ impl Component for PwtResetButton {
     }
 }
 
-impl Into<VNode> for ResetButton {
-    fn into(self) -> VNode {
-        let comp = VComp::new::<PwtResetButton>(Rc::new(self), None);
+impl From<ResetButton> for VNode {
+    fn from(val: ResetButton) -> Self {
+        let comp = VComp::new::<PwtResetButton>(Rc::new(val), None);
         VNode::from(comp)
     }
 }
index 59cbd58584ce72098c351f4ff8475fe25a4b2b83..36a056ba7ea04920bfe9923fe5d8ed6b7827ac6f 100644 (file)
@@ -216,7 +216,7 @@ impl<S: DataStore + 'static> ManagedField for SelectorField<S> {
 
         if !props.store.is_empty() {
             if let Some(validate) = &props.validate {
-                validate.apply(&(value.clone().into(), props.store.clone()))?;
+                validate.apply(&(value.clone(), props.store.clone()))?;
             }
         } else {
             // Return Ok if we have no data (i.e. because eof load error),
@@ -303,20 +303,18 @@ impl<S: DataStore + 'static> ManagedField for SelectorField<S> {
                 let state = ctx.state();
                 let value = state.value.as_str().unwrap_or("").to_owned();
 
-                if self.load_error.is_none() {
-                    if value.is_empty() {
-                        let mut default = props.default.clone();
+                if self.load_error.is_none() && value.is_empty() {
+                    let mut default = props.default.clone();
 
-                        if default.is_none() && props.autoselect {
-                            if let Some((_pos, node)) = props.store.filtered_data().next() {
-                                default = Some(AttrValue::from(node.key().to_string()));
-                            }
+                    if default.is_none() && props.autoselect {
+                        if let Some((_pos, node)) = props.store.filtered_data().next() {
+                            default = Some(AttrValue::from(node.key().to_string()));
                         }
+                    }
 
-                        if let Some(default) = default {
-                            ctx.link().update_value(default.to_string());
-                            ctx.link().update_default(default.to_string());
-                        }
+                    if let Some(default) = default {
+                        ctx.link().update_value(default.to_string());
+                        ctx.link().update_default(default.to_string());
                     }
                 }
                 ctx.link().validate(); // re-evaluate
index 69b0d45c3fccbc33cbc86006f6b4186ff6d1e087..3e6d224c8ed8b76092ba8c0fd71b74aefb192289 100644 (file)
@@ -45,6 +45,12 @@ pub struct SubmitButton {
     pub class: Classes,
 }
 
+impl Default for SubmitButton {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl SubmitButton {
     /// Createa new instance.
     pub fn new() -> Self {
@@ -171,9 +177,9 @@ impl Component for PwtSubmitButton {
     }
 }
 
-impl Into<VNode> for SubmitButton {
-    fn into(self) -> VNode {
-        let comp = VComp::new::<PwtSubmitButton>(Rc::new(self), None);
+impl From<SubmitButton> for VNode {
+    fn from(val: SubmitButton) -> Self {
+        let comp = VComp::new::<PwtSubmitButton>(Rc::new(val), None);
         VNode::from(comp)
     }
 }
index d620ae587bac2b20e5bc3d95718741ebdf7eea07..bf63a495c31d08c61c28a2a24a97136d84dd41bf 100644 (file)
@@ -67,6 +67,12 @@ pub struct TextArea {
     pub on_input: Option<Callback<String>>,
 }
 
+impl Default for TextArea {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl TextArea {
     /// Create a new instance.
     pub fn new() -> Self {
index e6d46186863719b7bc5bf3bf53a690098cfb0f4e..32cbcecb40db0365e11c7a64020fa75b8d951427 100644 (file)
@@ -54,6 +54,12 @@ pub struct TristateBoolean {
     pub on_change: Option<Callback<Tristate>>,
 }
 
+impl Default for TristateBoolean {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl TristateBoolean {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -123,7 +129,7 @@ impl ManagedField for PwtTristateBoolean {
         // fixme: value = force_value.to_string();
         //}
 
-        let value: Value = value.clone().into();
+        let value: Value = value.clone();
 
         let default = match props.default {
             None => Value::Null,
index aebad1947b378add757387cccd87abba2a924c93..03c90acaeee26af384af566fa5e15e039232d7fd 100644 (file)
@@ -153,17 +153,18 @@ impl<S: DataStore + 'static> Component for PwtGridPicker<S> {
     fn create(ctx: &Context<Self>) -> Self {
         let props = ctx.props();
         let on_select = props.on_select.clone();
-        let selection = props
-            .selection
-            .clone()
-            .unwrap_or_else(|| Selection::new())
-            .on_select(move |s: Selection| {
-                if let Some(key) = s.selected_key() {
-                    if let Some(on_select) = &on_select {
-                        on_select.emit(key);
+        let selection =
+            props
+                .selection
+                .clone()
+                .unwrap_or_default()
+                .on_select(move |s: Selection| {
+                    if let Some(key) = s.selected_key() {
+                        if let Some(on_select) = &on_select {
+                            on_select.emit(key);
+                        }
                     }
-                }
-            });
+                });
 
         let mut me = Self {
             _phantom: PhantomData::<S>,
@@ -205,13 +206,9 @@ impl<S: DataStore + 'static> Component for PwtGridPicker<S> {
             .node_ref(props.node_ref.clone())
             .class("pwt-flex-fill pwt-overflow-auto");
 
-        let show_filter = props.show_filter.unwrap_or_else(|| {
-            if self.store.data_len() > 10 {
-                true
-            } else {
-                false
-            }
-        });
+        let show_filter = props
+            .show_filter
+            .unwrap_or_else(|| self.store.data_len() > 10);
 
         if show_filter {
             let filter_invalid = false;
@@ -233,7 +230,7 @@ impl<S: DataStore + 'static> Component for PwtGridPicker<S> {
                             "is-valid"
                         })
                         .attribute("value", self.filter.clone())
-                        .attribute("aria-invalid", filter_invalid.then(|| "true"))
+                        .attribute("aria-invalid", filter_invalid.then_some("true"))
                         .oninput(ctx.link().callback(move |event: InputEvent| {
                             let input: HtmlInputElement = event.target_unchecked_into();
                             Msg::FilterUpdate(input.value())
@@ -249,10 +246,10 @@ impl<S: DataStore + 'static> Component for PwtGridPicker<S> {
     }
 }
 
-impl<S: DataStore + 'static> Into<VNode> for GridPicker<S> {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtGridPicker<S>>(Rc::new(self), key);
+impl<S: DataStore + 'static> From<GridPicker<S>> for VNode {
+    fn from(val: GridPicker<S>) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtGridPicker<S>>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 7c59f34a303179cd55a72db66599a4089add8c6a..c147f31921f4af219aba54bb96aa932746df9d0b 100644 (file)
@@ -10,6 +10,12 @@ use crate::props::{FieldStdProps, WidgetStdProps};
 #[derive(Clone, PartialEq, Properties)]
 pub struct Input {}
 
+impl Default for Input {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Input {
     /// Creates a new instance.
     pub fn new() -> Self {
@@ -29,11 +35,11 @@ impl Input {
     }
 }
 
-impl Into<VTag> for Input {
-    fn into(self) -> VTag {
-        let mut attributes = self.std_props.cumulate_attributes(None::<&str>);
+impl From<Input> for VTag {
+    fn from(val: Input) -> Self {
+        let mut attributes = val.std_props.cumulate_attributes(None::<&str>);
         let attr_map = attributes.get_mut_index_map();
-        self.input_props.cumulate_attributes(attr_map);
+        val.input_props.cumulate_attributes(attr_map);
 
         let value = attr_map
             .get(&AttrValue::Static("value"))
@@ -41,15 +47,15 @@ impl Into<VTag> for Input {
         let checked = attr_map
             .get(&AttrValue::Static("checked"))
             .is_some()
-            .then(|| true);
+            .then_some(true);
 
-        let listeners = Listeners::Pending(self.listeners.listeners.into_boxed_slice());
+        let listeners = Listeners::Pending(val.listeners.listeners.into_boxed_slice());
 
         VTag::__new_input(
             value,
             checked,
-            self.std_props.node_ref,
-            self.std_props.key,
+            val.std_props.node_ref,
+            val.std_props.key,
             attributes,
             listeners,
         )
index 5f2868fb5ecac6b6100ad36d5aafd0b2c6c6c99a..16f5d4b1b5c2a3d6c8f8349d47d9c9a9168a457d 100644 (file)
@@ -217,7 +217,7 @@ impl InputPanel {
         let style = if visible {
             format!("grid-row: {};", row)
         } else {
-            format!("display: none;")
+            "display: none;".to_string()
         };
 
         let label_id = crate::widget::get_unique_element_id();
@@ -360,43 +360,43 @@ impl Default for InputPanel {
     }
 }
 
-impl Into<VTag> for InputPanel {
-    fn into(mut self) -> VTag {
-        if self.two_column {
-            self.add_class("pwt-form-grid-col4")
+impl From<InputPanel> for VTag {
+    fn from(mut val: InputPanel) -> Self {
+        if val.two_column {
+            val.add_class("pwt-form-grid-col4")
         } else {
-            self.add_class("pwt-form-grid-col2")
+            val.add_class("pwt-form-grid-col2")
         }
 
-        if self.label_width.is_some() || self.field_width.is_some() {
+        if val.label_width.is_some() || val.field_width.is_some() {
             let mut column_template = format!(
                 "{} {}",
-                self.label_width
+                val.label_width
                     .as_deref()
                     .unwrap_or("minmax(130px, 0.65fr)"),
-                self.field_width.as_deref().unwrap_or("minmax(200px, 1fr)")
+                val.field_width.as_deref().unwrap_or("minmax(200px, 1fr)")
             );
 
-            if self.two_column {
+            if val.two_column {
                 column_template = format!(
                     "{} calc(var(--pwt-spacer-4) * 2) {}",
                     column_template, column_template
                 );
             }
 
-            self.set_style("grid-template-columns", column_template.to_string());
+            val.set_style("grid-template-columns", column_template.to_string());
         }
 
-        let attributes = self.std_props.cumulate_attributes(None::<&str>);
+        let attributes = val.std_props.cumulate_attributes(None::<&str>);
 
-        let listeners = Listeners::Pending(self.listeners.listeners.into_boxed_slice());
+        let listeners = Listeners::Pending(val.listeners.listeners.into_boxed_slice());
 
-        let children = VList::with_children(self.children, None);
+        let children = VList::with_children(val.children, None);
 
         VTag::__new_other(
             Cow::Borrowed("div"),
-            self.std_props.node_ref,
-            self.std_props.key,
+            val.std_props.node_ref,
+            val.std_props.key,
             attributes,
             listeners,
             children.into(),
index ecb2cee9461821ff87d605ff19ae17e9da308f54..588cfab8172f1d49f18903c44a904cc330d6db5c 100644 (file)
@@ -49,6 +49,12 @@ pub struct LanguageSelector {
     pub class: Classes,
 }
 
+impl Default for LanguageSelector {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl LanguageSelector {
     pub fn new() -> Self {
         yew::props!(Self {})
@@ -87,7 +93,7 @@ impl Component for PwtLanguageSelector {
 
         let mut lang = Language::load();
         if lang.is_empty() {
-            if languages.iter().find(|info| info.lang == "en").is_some() {
+            if languages.iter().any(|info| info.lang == "en") {
                 lang = "en".into();
             } else if let Some(first) = languages.first().map(|info| info.lang.clone()) {
                 lang = first;
@@ -159,9 +165,9 @@ impl Component for PwtLanguageSelector {
     }
 }
 
-impl Into<VNode> for LanguageSelector {
-    fn into(self) -> VNode {
-        let comp = VComp::new::<PwtLanguageSelector>(Rc::new(self), None);
+impl From<LanguageSelector> for VNode {
+    fn from(val: LanguageSelector) -> Self {
+        let comp = VComp::new::<PwtLanguageSelector>(Rc::new(val), None);
         VNode::from(comp)
     }
 }
index 17134a12e5692bac8fa36dc047a18668836ba6fe..2613fb110cb1b738bc2195cafc011d92ae250177 100644 (file)
@@ -60,18 +60,18 @@ impl ListTile {
     }
 }
 
-impl Into<VTag> for ListTile {
-    fn into(self) -> VTag {
+impl From<ListTile> for VTag {
+    fn from(val: ListTile) -> Self {
         let classes = classes!(
             "pwt-list-tile",
-            self.interactive.then(|| "pwt-interactive"),
-            self.disabled.then(|| "disabled")
+            val.interactive.then_some("pwt-interactive"),
+            val.disabled.then_some("disabled")
         );
-        self.std_props.into_vtag(
+        val.std_props.into_vtag(
             Cow::Borrowed("div"),
             Some(classes),
-            Some(self.listeners),
-            Some(self.children),
+            Some(val.listeners),
+            Some(val.children),
         )
     }
 }
index 2f7e36acf281a77398d1de478c4f800635b8aa41..519a63453cebff178c8ac4c08365d7c580f9f562 100644 (file)
@@ -139,7 +139,7 @@ impl SizeAccumulator {
     fn _get_row_height(&self, index: usize, min_row_height: u64) -> u64 {
         self.height_list
             .get(index)
-            .map(|v| *v)
+            .copied()
             .unwrap_or(min_row_height)
     }
 
@@ -275,21 +275,20 @@ impl PwtList {
             .style("top", format!("{}px", self.scroll_info.offset));
 
         let prefetch_count = props.prefetch_count as u64;
-        if self.scroll_info.end > self.scroll_info.start {
-            if self.scroll_info.start > prefetch_count {
-                for index in (self.scroll_info.start - prefetch_count)..self.scroll_info.start {
-                    // log::info!("ADD CACHED ROW {index}");
-
-                    let row = ListTileObserver::new(props.renderer.emit(index))
-                        .key(format!("row-{index}"))
-                        .force_height(0)
-                        .tile_pos(index)
-                        .separator(props.separator)
-                        .resize_callback(Some(self.tile_resize_callback.clone()));
-
-                    //row.set_attribute("role", "listitem");
-                    content.add_child(row);
-                }
+        if self.scroll_info.end > self.scroll_info.start && self.scroll_info.start > prefetch_count
+        {
+            for index in (self.scroll_info.start - prefetch_count)..self.scroll_info.start {
+                // log::info!("ADD CACHED ROW {index}");
+
+                let row = ListTileObserver::new(props.renderer.emit(index))
+                    .key(format!("row-{index}"))
+                    .force_height(0)
+                    .tile_pos(index)
+                    .separator(props.separator)
+                    .resize_callback(Some(self.tile_resize_callback.clone()));
+
+                //row.set_attribute("role", "listitem");
+                content.add_child(row);
             }
         }
 
@@ -435,7 +434,7 @@ impl Component for PwtList {
             if let Some(el) = &viewport_el {
                 let link = ctx.link().clone();
                 let size_observer =
-                    DomSizeObserver::new(&el, move |(width, height, client_width, _)| {
+                    DomSizeObserver::new(el, move |(width, height, client_width, _)| {
                         link.send_message(Msg::ViewportResize(width, height, width - client_width));
                     });
                 self.viewport_size_observer = Some(size_observer);
index fe654e243214d8faf2b72e98f7f50c7947470272..25e07a60ac5eb3ed258d182f5b0eb768de289dfb 100644 (file)
@@ -99,7 +99,7 @@ impl Component for PwtMask {
 
         let mut mask = Container::new()
             .class("pwt-load-mask")
-            .class(props.visible.then(|| "visible"));
+            .class(props.visible.then_some("visible"));
 
         if props.visible {
             mask.add_child(
index b0f45209cb988125cc7e1c7d3946e4316dfb34a2..50f85b39dba97cdcbfae5b629e20e4c343fc8481 100644 (file)
@@ -143,7 +143,7 @@ pub struct PwtMenuButton {
 impl PwtMenuButton {
     fn restore_focus(&mut self, props: &MenuButton) {
         if let Some(node) = props.std_props.node_ref.get() {
-            if let Some(el) = node.dyn_into::<web_sys::HtmlElement>().ok() {
+            if let Ok(el) = node.dyn_into::<web_sys::HtmlElement>() {
                 let _ = el.focus();
             }
         }
@@ -230,15 +230,13 @@ impl Component for PwtMenuButton {
                         .menu_controller(self.menu_controller.clone())
                         .on_close(ctx.link().callback(|_| Msg::CloseMenu)),
                 )
-            } else if let Some(m) = &props.menu {
-                Some(
+            } else {
+                props.menu.as_ref().map(|m| {
                     m.clone()
                         .autofocus(true)
                         .menu_controller(self.menu_controller.clone())
-                        .on_close(ctx.link().callback(|_| Msg::CloseMenu)),
-                )
-            } else {
-                None
+                        .on_close(ctx.link().callback(|_| Msg::CloseMenu))
+                })
             };
 
             Container::new()
@@ -251,7 +249,7 @@ impl Component for PwtMenuButton {
         let mut button = Button::new(&props.text)
             .show_arrow(props.show_arrow)
             .attribute("aria-haspopup", "true")
-            .attribute("aria-expanded", self.show_submenu.then(|| "true"))
+            .attribute("aria-expanded", self.show_submenu.then_some("true"))
             .tabindex(props.tabindex)
             .icon_class(props.icon_class.clone());
 
index 85059c65f68d53a2369612d9b876c327afb0a503..9fd93120c4947e64b935280ad81e069b6fdab4d9 100644 (file)
@@ -111,9 +111,7 @@ impl ManagedField for MenuCheckboxField {
     type Properties = MenuCheckbox;
     type ValidateClosure = ();
 
-    fn validation_args(_props: &Self::Properties) -> Self::ValidateClosure {
-        ()
-    }
+    fn validation_args(_props: &Self::Properties) -> Self::ValidateClosure {}
 
     fn setup(props: &MenuCheckbox) -> ManagedFieldState {
         let on_value = props.value.as_deref().unwrap_or("on").to_string();
@@ -229,12 +227,10 @@ impl ManagedField for MenuCheckboxField {
                 } else {
                     "fa-circle-o"
                 }
+            } else if checked {
+                "fa-check-square-o"
             } else {
-                if checked {
-                    "fa-check-square-o"
-                } else {
-                    "fa-square-o"
-                }
+                "fa-square-o"
             },
             "pwt-menu-item-icon",
         );
@@ -252,8 +248,8 @@ impl ManagedField for MenuCheckboxField {
 
         Container::new()
             .class("pwt-menu-item")
-            .attribute("tabindex", (!disabled).then(|| "-1"))
-            .attribute("aria-disabled", disabled.then(|| "true"))
+            .attribute("tabindex", (!disabled).then_some("-1"))
+            .attribute("aria-disabled", disabled.then_some("true"))
             .attribute(
                 "role",
                 if props.radio_group {
@@ -262,7 +258,7 @@ impl ManagedField for MenuCheckboxField {
                     "menuitemcheckbox"
                 },
             )
-            .attribute("aria-checked", checked.then(|| "true"))
+            .attribute("aria-checked", checked.then_some("true"))
             .onclick(onclick)
             .onkeydown(onkeydown)
             .with_child(icon)
@@ -271,9 +267,9 @@ impl ManagedField for MenuCheckboxField {
     }
 }
 
-impl Into<VNode> for MenuCheckbox {
-    fn into(self) -> VNode {
-        let comp = VComp::new::<ManagedFieldMaster<MenuCheckboxField>>(Rc::new(self), None);
+impl From<MenuCheckbox> for VNode {
+    fn from(val: MenuCheckbox) -> Self {
+        let comp = VComp::new::<ManagedFieldMaster<MenuCheckboxField>>(Rc::new(val), None);
         VNode::from(comp)
     }
 }
index 75361c203f38ac6e3e294e0be16df18ac732ac27..4d8d5d5e93af02650a3fbd77f04b3b4cd4d83f32 100644 (file)
@@ -283,13 +283,13 @@ impl Component for PwtMenuItem {
             } else {
                 "pwt-menu-item"
             })
-            .attribute("tabindex", (!props.focusable).then(|| "-1"))
-            .attribute("aria-disabled", props.disabled.then(|| "true"))
+            .attribute("tabindex", (!props.focusable).then_some("-1"))
+            .attribute("aria-disabled", props.disabled.then_some("true"))
             .attribute("role", "menuitem")
-            .attribute("aria-haspopup", has_submenu.then(|| "true"))
+            .attribute("aria-haspopup", has_submenu.then_some("true"))
             .attribute(
                 "aria-expanded",
-                has_submenu.then(|| if show_submenu { "true" } else { "false" }),
+                has_submenu.then_some(if show_submenu { "true" } else { "false" }),
             )
             .with_optional_child(icon)
             .with_child(html! {<span class="pwt-flex-fill">{props.text.clone()}</span>})
@@ -330,9 +330,9 @@ impl Component for PwtMenuItem {
     }
 }
 
-impl Into<VNode> for MenuItem {
-    fn into(self) -> VNode {
-        let comp = VComp::new::<PwtMenuItem>(Rc::new(self), None);
+impl From<MenuItem> for VNode {
+    fn from(val: MenuItem) -> Self {
+        let comp = VComp::new::<PwtMenuItem>(Rc::new(val), None);
         VNode::from(comp)
     }
 }
index fbbb9ca041178ccdc68aff2a0031820f20e1ebe2..e24ea6ec9aaad737ec0abb3a4c93bf2c3a2974f3 100644 (file)
@@ -127,6 +127,12 @@ impl MenuBar {
     }
 }
 
+impl Default for Menu {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Menu {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -237,10 +243,7 @@ impl PwtMenu {
             None => return false,
         };
 
-        let res = match focus_el.focus() {
-            Ok(_) => true,
-            Err(_) => false,
-        };
+        let res = focus_el.focus().is_ok();
 
         if has_focus {
             //log::info!("FOCUS {:?}", focus_el);
@@ -380,7 +383,7 @@ impl Component for PwtMenu {
                     self.set_cursor(cursor, true);
                 }
                 //log::info!("CLOSE {} {} {}", self.unique_id, self.show_submenu, self.inside_submenu);
-                return true;
+                true
             }
             Msg::Redraw => true,
             Msg::Next => {
@@ -432,7 +435,7 @@ impl Component for PwtMenu {
                         }
                     }
                     None => {
-                        if props.children.len() == 0 {
+                        if props.children.is_empty() {
                             return false;
                         } else {
                             props.children.len() - 1
@@ -481,7 +484,7 @@ impl Component for PwtMenu {
                     }
                 }
 
-                if show == false {
+                if !show {
                     if let Some(on_close) = &props.on_close {
                         //log::info!("PROPAGATE CLOSE {} {}", self.unique_id, show);
                         on_close.emit(());
@@ -606,7 +609,7 @@ impl Component for PwtMenu {
                     .attribute("id", item_id.clone())
                     .attribute("data-index", i.to_string()) // fixme: remove
                     .attribute("role", "none")
-                    .class((active).then(|| "active"))
+                    .class((active).then_some("active"))
                     .with_child(child)
                     .onkeydown({
                         let link = ctx.link().clone();
@@ -718,9 +721,9 @@ impl Component for PwtMenu {
     }
 }
 
-impl Into<VNode> for Menu {
-    fn into(self) -> VNode {
-        let comp = VComp::new::<PwtMenu>(Rc::new(self), None);
+impl From<Menu> for VNode {
+    fn from(val: Menu) -> Self {
+        let comp = VComp::new::<PwtMenu>(Rc::new(val), None);
         VNode::from(comp)
     }
 }
index 613350b2fec9bc0631a8ff520fa4ef5c1eed013d..f081b8d5ae638a0ac9ae2eb16dd497c0bb55c0b8 100644 (file)
@@ -92,15 +92,15 @@ impl Meter {
     }
 }
 
-impl Into<VTag> for Meter {
-    fn into(self) -> VTag {
-        let percentage = ((self.value - self.min).max(0.0) / (self.max - self.min)).clamp(0.0, 1.0);
+impl From<Meter> for VTag {
+    fn from(val: Meter) -> Self {
+        let percentage = ((val.value - val.min).max(0.0) / (val.max - val.min)).clamp(0.0, 1.0);
 
-        let distance_to_optimum = if let Some(optimum) = self.optimum {
-            if optimum > self.value {
-                self.get_range_index(optimum) - self.get_range_index(self.value)
+        let distance_to_optimum = if let Some(optimum) = val.optimum {
+            if optimum > val.value {
+                val.get_range_index(optimum) - val.get_range_index(val.value)
             } else {
-                self.get_range_index(self.value) - self.get_range_index(optimum)
+                val.get_range_index(val.value) - val.get_range_index(optimum)
             }
         } else {
             0
@@ -109,8 +109,8 @@ impl Into<VTag> for Meter {
         let mut children = Vec::new();
         let mut class = classes!("pwt-meter");
 
-        if let Some(render_text) = &self.render_text {
-            let text = render_text.apply(&self.value);
+        if let Some(render_text) = &val.render_text {
+            let text = render_text.apply(&val.value);
             children.push(
                 Container::new()
                     .class("pwt-meter-text")
@@ -121,7 +121,7 @@ impl Into<VTag> for Meter {
             class.push("pwt-meter-small")
         }
 
-        if self.animated {
+        if val.animated {
             class.push("pwt-animated");
         }
 
@@ -133,7 +133,7 @@ impl Into<VTag> for Meter {
                 .into(),
         );
 
-        self.std_props
+        val.std_props
             .into_vtag(Cow::Borrowed("div"), Some(class), None, Some(children))
     }
 }
index 76bc46f3b2cea10f3d61869d879b031d8682cdae..1cae06b3f5689dfe09405b34a98ecc2786dde9bc 100644 (file)
@@ -247,8 +247,8 @@ impl Component for PwtMiniScroll {
         let left = Container::new()
             .node_ref(self.handle_ref.clone())
             .class("pwt-mini-scroll-left-arrow")
-            .class(arrow_visible.then(|| "visible"))
-            .class((self.pos <= 0.0).then(|| "disabled"))
+            .class(arrow_visible.then_some("visible"))
+            .class((self.pos <= 0.0).then_some("disabled"))
             .with_child(html! {<i class="fa fa-chevron-left"/>})
             .onpointerdown(ctx.link().callback(|_| Msg::ScrollLeft))
             .onpointerout(ctx.link().callback(|_| Msg::ScrollStop))
@@ -256,8 +256,8 @@ impl Component for PwtMiniScroll {
 
         let right = Container::new()
             .class("pwt-mini-scroll-right-arrow")
-            .class(arrow_visible.then(|| "visible"))
-            .class((self.pos >= 1.0).then(|| "disabled"))
+            .class(arrow_visible.then_some("visible"))
+            .class((self.pos >= 1.0).then_some("disabled"))
             .with_child(html! {<i class="fa fa-chevron-right"/>})
             .onpointerdown(ctx.link().callback(|_| Msg::ScrollRight))
             .onpointerout(ctx.link().callback(|_| Msg::ScrollStop))
index 7cd74408110f601135ac47009540cc12ae480a90..94119c59cfa4f1673584fa6f93a5c37a60ac376c 100644 (file)
@@ -86,6 +86,12 @@ pub struct Menu {
     pub children: Vec<MenuEntry>,
 }
 
+impl Default for Menu {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Menu {
     /// Create a new instance.
     pub fn new() -> Self {
index 7335d67ebc0f4a924ed81292fd432403522b389d..ed4bb1e55dfcd09423d5e93f20b5d45baba58cc0 100644 (file)
@@ -249,9 +249,11 @@ impl PwtNavigationDrawer {
                 html! {<span style={format!("width: {}rem", (indent_level as f32) * 1.0)}/>}
             }))
             // add optional icon on the left
-            .with_optional_child(item.icon_class.as_ref().and_then(|icon| {
-                Some(html! { <i class={classes!(icon.to_string(), "pwt-nav-menu-icon")}/>})
-            }))
+            .with_optional_child(
+                item.icon_class.as_ref().map(
+                    |icon| html! { <i class={classes!(icon.to_string(), "pwt-nav-menu-icon")}/>},
+                ),
+            )
             // add memu label
             .with_child(html! {<div class="pwt-text-truncate pwt-flex-fill">{&item.label}</div>})
             // add optional menu-open icon
@@ -336,28 +338,25 @@ impl PwtNavigationDrawer {
 
         fn find_item_recursive<'a>(menu: &'a [MenuEntry], desired: &Key) -> Option<&'a MenuEntry> {
             for menu in menu.iter() {
-                match menu {
-                    MenuEntry::Item(item) => {
-                        if item.key.as_ref() == Some(desired) {
-                            return Some(menu);
-                        }
+                if let MenuEntry::Item(item) = menu {
+                    if item.key.as_ref() == Some(desired) {
+                        return Some(menu);
+                    }
 
-                        if let Some(submenu) = &item.submenu {
-                            let res = find_item_recursive(&submenu.children[..], desired);
-                            if res.is_some() {
-                                return res;
-                            }
+                    if let Some(submenu) = &item.submenu {
+                        let res = find_item_recursive(&submenu.children[..], desired);
+                        if res.is_some() {
+                            return res;
                         }
                     }
-                    _ => {}
                 };
             }
             None
         }
 
-        match find_item_recursive(&props.menu.children, &desired) {
+        match find_item_recursive(&props.menu.children, desired) {
             Some(entry @ MenuEntry::Item(item)) => match &item.submenu {
-                None => item.selectable.then(|| entry),
+                None => item.selectable.then_some(entry),
                 Some(submenu) => {
                     if item.selectable {
                         Some(entry)
@@ -472,7 +471,7 @@ impl Component for PwtNavigationDrawer {
                     None
                 };
 
-                if &self.active == &key {
+                if self.active == key {
                     return false;
                 }
 
@@ -485,7 +484,7 @@ impl Component for PwtNavigationDrawer {
                 }
 
                 if let Some(key) = &key {
-                    self.emit_item_activate(&key, ctx);
+                    self.emit_item_activate(key, ctx);
                 }
 
                 if let Some(on_select) = &props.on_select {
@@ -611,10 +610,10 @@ impl Component for PwtNavigationDrawer {
     }
 }
 
-impl Into<VNode> for NavigationDrawer {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtNavigationDrawer>(Rc::new(self), key);
+impl From<NavigationDrawer> for VNode {
+    fn from(val: NavigationDrawer) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtNavigationDrawer>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 79730e60312a7b71fa5e5af6daf0755d3b803a1d..9fd470e0b666c7a8e2994c363203f683d9a6a08d 100644 (file)
@@ -26,6 +26,12 @@ pub struct Panel {
     pub header_class: Classes,
 }
 
+impl Default for Panel {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Panel {
     /// Creates a new instance.
     pub fn new() -> Self {
@@ -66,27 +72,27 @@ impl Panel {
     }
 }
 
-impl Into<VTag> for Panel {
-    fn into(mut self) -> VTag {
-        self.add_class("pwt-panel");
+impl From<Panel> for VTag {
+    fn from(mut val: Panel) -> Self {
+        val.add_class("pwt-panel");
 
-        if self.title.is_some() || !self.tools.is_empty() {
-            let header = create_panel_title(self.title, self.tools)
+        if val.title.is_some() || !val.tools.is_empty() {
+            let header = create_panel_title(val.title, val.tools)
                 .class("pwt-panel-header")
-                .class(self.header_class);
-            self.children.insert(0, header.into());
+                .class(val.header_class);
+            val.children.insert(0, header.into());
         }
 
-        let attributes = self.std_props.cumulate_attributes(None::<&str>);
+        let attributes = val.std_props.cumulate_attributes(None::<&str>);
 
-        let listeners = Listeners::Pending(self.listeners.listeners.into_boxed_slice());
+        let listeners = Listeners::Pending(val.listeners.listeners.into_boxed_slice());
 
-        let children = VList::with_children(self.children, None);
+        let children = VList::with_children(val.children, None);
 
         VTag::__new_other(
             Cow::Borrowed("div"),
-            self.std_props.node_ref,
-            self.std_props.key,
+            val.std_props.node_ref,
+            val.std_props.key,
             attributes,
             listeners,
             children.into(),
index a0d82c494443ded8e2f5aae40f7433e6ab59446e..87ccdf2dd94ad4ba8c22a872e4b17d06f497cbb6 100644 (file)
@@ -42,11 +42,11 @@ impl Progress {
     }
 }
 
-impl Into<VTag> for Progress {
-    fn into(self) -> VTag {
-        let max = self.max.unwrap_or(1.0);
+impl From<Progress> for VTag {
+    fn from(val: Progress) -> Self {
+        let max = val.max.unwrap_or(1.0);
 
-        let bar = match self.value {
+        let bar = match val.value {
             Some(value) => {
                 let percentage = (value / max).clamp(0.0, 1.0);
                 Container::new()
@@ -57,7 +57,7 @@ impl Into<VTag> for Progress {
             None => Container::new().class("pwt-progress-infinite").into(),
         };
 
-        self.std_props.into_vtag(
+        val.std_props.into_vtag(
             Cow::Borrowed("div"),
             Some("pwt-progress"),
             None,
index 47fa5fedc6e85dac2b60af11a03450e20b7cf3d8..2cd52307e10f87d09c264043916bcda84eba3949 100644 (file)
@@ -31,6 +31,12 @@ use crate::prelude::*;
 #[derive(Debug, Clone, PartialEq, Properties)]
 pub struct Row {}
 
+impl Default for Row {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Row {
     /// Create a new instance.
     pub fn new() -> Self {
@@ -66,18 +72,18 @@ impl Row {
     }
 }
 
-impl Into<VTag> for Row {
-    fn into(self) -> VTag {
-        let attributes = self.std_props.cumulate_attributes(None::<&str>);
+impl From<Row> for VTag {
+    fn from(val: Row) -> Self {
+        let attributes = val.std_props.cumulate_attributes(None::<&str>);
 
-        let listeners = Listeners::Pending(self.listeners.listeners.into_boxed_slice());
+        let listeners = Listeners::Pending(val.listeners.listeners.into_boxed_slice());
 
-        let children = VList::with_children(self.children, None);
+        let children = VList::with_children(val.children, None);
 
         VTag::__new_other(
             Cow::Borrowed("div"),
-            self.std_props.node_ref,
-            self.std_props.key,
+            val.std_props.node_ref,
+            val.std_props.key,
             attributes,
             listeners,
             children.into(),
index c50032e721b805e5952770510ee7af3fabb247f9..9b514f1633e17461cfe1ef346a57b1c8b661353c 100644 (file)
@@ -13,6 +13,12 @@ pub struct SegmentedButton {
     buttons: Vec<Button>,
 }
 
+impl Default for SegmentedButton {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl SegmentedButton {
     /// Create a new segmented button.
     pub fn new() -> Self {
index f886f220034ba53cae800dc0dec6c2607c9feb95..8ba17706a6e528ab5a3d604924406a77c323862f 100644 (file)
@@ -73,6 +73,12 @@ pub struct SelectionView {
     pub page_cache: bool,
 }
 
+impl Default for SelectionView {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl SelectionView {
     /// Creates a new instance.
     pub fn new() -> Self {
@@ -122,7 +128,7 @@ impl Component for PwtSelectionView {
         let _selection_observer = props
             .selection
             .clone()
-            .unwrap_or(Selection::new())
+            .unwrap_or_default()
             .add_listener(ctx.link().callback(Msg::SelectionChange));
 
         let (visibility, _visibility_handle) = ctx
@@ -166,7 +172,7 @@ impl Component for PwtSelectionView {
             self._selection_observer = props
                 .selection
                 .clone()
-                .unwrap_or(Selection::new())
+                .unwrap_or_default()
                 .add_listener(ctx.link().callback(Msg::SelectionChange));
         }
         true
index a0220e7f1c93d088dd67e806e3b998a3a690ff53..f779f45581719ee62b8df70411c2299d28c8e2bf 100644 (file)
@@ -96,10 +96,10 @@ impl<W: WidgetBuilder + PartialEq + Clone + 'static> Component for PwtSizeObserv
     }
 }
 
-impl<W: WidgetBuilder + PartialEq + Clone + 'static> Into<VNode> for SizeObserver<W> {
-    fn into(self) -> VNode {
-        let key = self.content.as_std_props().key.clone();
-        let comp = VComp::new::<PwtSizeObserver<W>>(Rc::new(self), key);
+impl<W: WidgetBuilder + PartialEq + Clone + 'static> From<SizeObserver<W>> for VNode {
+    fn from(val: SizeObserver<W>) -> Self {
+        let key = val.content.as_std_props().key.clone();
+        let comp = VComp::new::<PwtSizeObserver<W>>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 50da0386661d0a8674835069cd0e589ba561b903..0be0a8c26ac67b2b78ba2044f020d32f55b64e03 100644 (file)
@@ -104,7 +104,7 @@ impl Pane {
 
     /// Method to set the initial pane size in pixels.
     pub fn set_size(&mut self, size: impl IntoPropValue<Option<usize>>) {
-        self.size = size.into_prop_value().map(|p| PaneSize::Pixel(p));
+        self.size = size.into_prop_value().map(PaneSize::Pixel);
     }
 
     /// Builder style method to set the initial pane size as flex.
@@ -115,7 +115,7 @@ impl Pane {
 
     /// Method to set the initial pane size as flex.
     pub fn set_flex(&mut self, flex: impl IntoPropValue<Option<usize>>) {
-        self.size = flex.into_prop_value().map(|f| PaneSize::Flex(f));
+        self.size = flex.into_prop_value().map(PaneSize::Flex);
     }
 
     /// Builder style method to set the initial pane size as fraction.
@@ -126,7 +126,7 @@ impl Pane {
 
     /// Method to set the initial pane size as fraction.
     pub fn set_fraction(&mut self, fraction: impl IntoPropValue<Option<f64>>) {
-        self.size = fraction.into_prop_value().map(|f| PaneSize::Fraction(f));
+        self.size = fraction.into_prop_value().map(PaneSize::Fraction);
     }
 
     /// Builder style method to set the minimal pane size in pixels.
@@ -137,7 +137,7 @@ impl Pane {
 
     /// Method to set the minimal pane size in pixels.
     pub fn set_min_size(&mut self, size: impl IntoPropValue<Option<usize>>) {
-        self.min_size = size.into_prop_value().map(|p| PaneSize::Pixel(p));
+        self.min_size = size.into_prop_value().map(PaneSize::Pixel);
     }
 
     /// Builder style method to set the minimal pane size as fraction.
@@ -148,7 +148,7 @@ impl Pane {
 
     /// Method to set the minimal pane size as fraction.
     pub fn set_min_fraction(&mut self, fraction: impl IntoPropValue<Option<f64>>) {
-        self.min_size = fraction.into_prop_value().map(|f| PaneSize::Fraction(f));
+        self.min_size = fraction.into_prop_value().map(PaneSize::Fraction);
     }
 
     /// Builder style method to set the maximal pane size in pixels.
@@ -159,7 +159,7 @@ impl Pane {
 
     /// Method to set the maximal pane size in pixels.
     pub fn set_max_size(&mut self, size: impl IntoPropValue<Option<usize>>) {
-        self.max_size = size.into_prop_value().map(|p| PaneSize::Pixel(p));
+        self.max_size = size.into_prop_value().map(PaneSize::Pixel);
     }
 
     /// Builder style method to set the maximal pane size as fraction.
@@ -170,7 +170,7 @@ impl Pane {
 
     /// Method to set the maximal pane size as fraction.
     pub fn set_max_fraction(&mut self, fraction: impl IntoPropValue<Option<f64>>) {
-        self.max_size = fraction.into_prop_value().map(|f| PaneSize::Fraction(f));
+        self.max_size = fraction.into_prop_value().map(PaneSize::Fraction);
     }
 
     /// Builder style method to add a html class
@@ -208,6 +208,12 @@ pub struct SplitPane {
     pub handle_size: usize,
 }
 
+impl Default for SplitPane {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl SplitPane {
     /// Creates a new instance
     pub fn new() -> Self {
@@ -424,9 +430,8 @@ impl PwtSplitPane {
             .unwrap_or(f64::MAX);
 
         let size = new_size.min(max).max(min);
-        let diff = size - current_size;
 
-        diff
+        size - current_size
     }
 
     fn resize_pane(&mut self, props: &SplitPane, child_index: usize, new_size1: f64) -> bool {
@@ -590,8 +595,8 @@ impl Component for PwtSplitPane {
                 let fraction = (width > 0f64).then(|| position / width);
                 children.push(self.create_splitter(ctx, i - 1, fraction));
             }
-            position += self.sizes.get(i).map(|s| *s).unwrap_or(0.0);
-            children.push(self.create_pane(ctx, i, &child))
+            position += self.sizes.get(i).copied().unwrap_or(0.0);
+            children.push(self.create_pane(ctx, i, child))
         }
 
         let mut container = yew::props!(Container {
index b5b596ba419d21cb9a7be1d009ef3bb6ed221f73..ade6b16a89452ef84cb9df92ed31b848373bc9a8 100644 (file)
@@ -246,7 +246,7 @@ impl Component for PwtTabBar {
             .map(|state_id| PersistentState::<String>::new(state_id.clone()));
 
         if let Some(active_cache) = &active_cache {
-            let last_active: &str = &*active_cache;
+            let last_active: &str = active_cache;
             if !last_active.is_empty() {
                 active = Some(Key::from(last_active));
             }
@@ -309,7 +309,7 @@ impl Component for PwtTabBar {
                 let key = selection.selected_key();
                 let key = get_active_or_default(props, &key);
 
-                if &self.active == &key {
+                if self.active == key {
                     return false;
                 }
 
@@ -318,7 +318,7 @@ impl Component for PwtTabBar {
 
                 if let Some(key) = &self.active {
                     if props.router {
-                        ctx.link().push_relative_route(&key);
+                        ctx.link().push_relative_route(key);
                     }
                 }
                 if let Some(on_select) = &props.on_select {
@@ -330,7 +330,7 @@ impl Component for PwtTabBar {
             // Handle internal selection changes
             Msg::Select(key, update_route) => {
                 let key = get_active_or_default(props, &key);
-                if &self.active == &key {
+                if self.active == key {
                     return false;
                 }
 
@@ -545,10 +545,10 @@ impl Component for PwtTabBar {
     }
 }
 
-impl Into<VNode> for TabBar {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtTabBar>(Rc::new(self), key);
+impl From<TabBar> for VNode {
+    fn from(val: TabBar) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtTabBar>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 457ade8c3c1d8e2b8114faf9bfcf5dc52580ee4b..9fd48f799b908f7c35a02e201db19e3f3533f25d 100644 (file)
@@ -48,6 +48,12 @@ pub struct TabBarItem {
     pub disabled: bool,
 }
 
+impl Default for TabBarItem {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl TabBarItem {
     /// Create a new instance.
     pub fn new() -> Self {
index 680ab9159055b6496a5524f081cbbb30c24dcb56..ce629b18d69dbf46c0ce9927e6350a9050949dca 100644 (file)
@@ -95,6 +95,12 @@ pub struct TabPanel {
     pub tab_bar_style: TabBarStyle,
 }
 
+impl Default for TabPanel {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl TabPanel {
     /// Creates a new instance.
     pub fn new() -> Self {
@@ -274,10 +280,10 @@ impl Component for PwtTabPanel {
     }
 }
 
-impl Into<VNode> for TabPanel {
-    fn into(self) -> VNode {
-        let key = self.key.clone();
-        let comp = VComp::new::<PwtTabPanel>(Rc::new(self), key);
+impl From<TabPanel> for VNode {
+    fn from(val: TabPanel) -> Self {
+        let key = val.key.clone();
+        let comp = VComp::new::<PwtTabPanel>(Rc::new(val), key);
         VNode::from(comp)
     }
 }
index 1a000e9ea3bbcafc0caaed8e2ab53e83e0a2b519..27153e46f84dae73263d4b1c84e36d2da3b28531 100644 (file)
@@ -14,6 +14,12 @@ pub struct ThemeDensitySelector {
     class: Classes,
 }
 
+impl Default for ThemeDensitySelector {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl ThemeDensitySelector {
     pub fn new() -> Self {
         yew::props!(Self {})
@@ -84,9 +90,9 @@ impl Component for PwtThemeDensitySelector {
     }
 }
 
-impl Into<VNode> for ThemeDensitySelector {
-    fn into(self) -> VNode {
-        let comp = VComp::new::<PwtThemeDensitySelector>(Rc::new(self), None);
+impl From<ThemeDensitySelector> for VNode {
+    fn from(val: ThemeDensitySelector) -> Self {
+        let comp = VComp::new::<PwtThemeDensitySelector>(Rc::new(val), None);
         VNode::from(comp)
     }
 }
index b05919b67d3a6a52549753ad094643faf6f7d65b..da9a8aad382d8e8e0cec71cb2e16f2442d32bc48 100644 (file)
@@ -188,9 +188,9 @@ impl Component for PwtThemeLoader {
     }
 }
 
-impl Into<VNode> for ThemeLoader {
-    fn into(self) -> VNode {
-        let comp = VComp::new::<PwtThemeLoader>(Rc::new(self), None);
+impl From<ThemeLoader> for VNode {
+    fn from(val: ThemeLoader) -> Self {
+        let comp = VComp::new::<PwtThemeLoader>(Rc::new(val), None);
         VNode::from(comp)
     }
 }
index 548e3c6e9c1858c1e9a000016fad117f23861922..38be29f73c03c9d62c2d5fb6a5441fc2ab8cc158 100644 (file)
@@ -14,6 +14,12 @@ pub struct ThemeModeSelector {
     class: Classes,
 }
 
+impl Default for ThemeModeSelector {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl ThemeModeSelector {
     pub fn new() -> Self {
         yew::props!(Self {})
@@ -59,7 +65,7 @@ impl Component for PwtThemeModeSelector {
                     ThemeMode::Dark => ThemeMode::Light,
                     ThemeMode::Light => ThemeMode::System,
                 };
-                return yew::Component::update(self, ctx, Msg::SetThemeMode(theme));
+                yew::Component::update(self, ctx, Msg::SetThemeMode(theme))
             }
             Msg::SetThemeMode(theme) => {
                 if let Err(err) = Theme::store_theme_mode(theme) {
@@ -96,9 +102,9 @@ impl Component for PwtThemeModeSelector {
     }
 }
 
-impl Into<VNode> for ThemeModeSelector {
-    fn into(self) -> VNode {
-        let comp = VComp::new::<PwtThemeModeSelector>(Rc::new(self), None);
+impl From<ThemeModeSelector> for VNode {
+    fn from(val: ThemeModeSelector) -> Self {
+        let comp = VComp::new::<PwtThemeModeSelector>(Rc::new(val), None);
         VNode::from(comp)
     }
 }
index 27ae97718bdd58db20a0b66d3a5add8aa1bb0626..42315262431d0ce6c744eb6e5d8a6cd5195b56b6 100644 (file)
@@ -13,6 +13,12 @@ pub struct ThemeNameSelector {
     class: Classes,
 }
 
+impl Default for ThemeNameSelector {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl ThemeNameSelector {
     pub fn new() -> Self {
         yew::props!(Self {})
@@ -76,7 +82,7 @@ impl Component for PwtThemeNameSelector {
         Combobox::new()
             .node_ref(self.combobox_ref.clone())
             .class(props.class.clone())
-            .on_change(ctx.link().callback(|v| Msg::SetThemeName(v)))
+            .on_change(ctx.link().callback(Msg::SetThemeName))
             .aria_label("Select Theme")
             .default(self.theme.clone())
             .required(true)
@@ -92,9 +98,9 @@ impl Component for PwtThemeNameSelector {
     }
 }
 
-impl Into<VNode> for ThemeNameSelector {
-    fn into(self) -> VNode {
-        let comp = VComp::new::<PwtThemeNameSelector>(Rc::new(self), None);
+impl From<ThemeNameSelector> for VNode {
+    fn from(val: ThemeNameSelector) -> Self {
+        let comp = VComp::new::<PwtThemeNameSelector>(Rc::new(val), None);
         VNode::from(comp)
     }
 }
index 44e52ce61bc5109645abf279141edde92fe15474..e988242bd3719928ff185010badc6f99ab562c2d 100644 (file)
@@ -45,6 +45,12 @@ pub struct Toolbar {
     pub scroll_mode: Option<MiniScrollMode>,
 }
 
+impl Default for Toolbar {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Toolbar {
     /// Create a new instance.
     pub fn new() -> Self {
index c229d0206e748dadc1606507a818b557486aef4c..1f996eb9ba622826fb15a9a6e8da784ffc2fa0bb 100644 (file)
@@ -91,10 +91,10 @@ impl<W: WidgetBuilder + PartialEq + Clone + 'static> Component for PwtVisibility
     }
 }
 
-impl<W: WidgetBuilder + PartialEq + Clone + 'static> Into<VNode> for VisibilityObserver<W> {
-    fn into(self) -> VNode {
-        let key = self.content.as_std_props().key.clone();
-        let comp = VComp::new::<PwtVisibilityObserver<W>>(Rc::new(self), key);
+impl<W: WidgetBuilder + PartialEq + Clone + 'static> From<VisibilityObserver<W>> for VNode {
+    fn from(val: VisibilityObserver<W>) -> Self {
+        let key = val.content.as_std_props().key.clone();
+        let comp = VComp::new::<PwtVisibilityObserver<W>>(Rc::new(val), key);
         VNode::from(comp)
     }
 }