[pdm-devel] [PATCH proxmox-yew-comp 09/15] use or_default and unwrap_or_default

Maximiliano Sandoval m.sandoval at proxmox.com
Mon Jan 13 15:27:19 CET 2025


Fixes:

warning: use of `or_insert` to construct default value
   --> src/apt_repositories.rs:335:55
    |
335 |         let inner = info_map.entry(info.path.clone()).or_insert(HashMap::new());
    |                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_or_default
    = note: `#[warn(clippy::unwrap_or_default)]` on by default

warning: use of `or_insert` to construct default value
   --> src/apt_repositories.rs:336:45
    |
336 |         let entry = inner.entry(info.index).or_insert(Vec::new());
    |                                             ^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_or_default

Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
 src/apt_repositories.rs           | 4 ++--
 src/configuration/network_edit.rs | 2 +-
 src/configuration/network_view.rs | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/apt_repositories.rs b/src/apt_repositories.rs
index 2998a5a..7149545 100644
--- a/src/apt_repositories.rs
+++ b/src/apt_repositories.rs
@@ -329,8 +329,8 @@ fn apt_configuration_to_tree(config: &APTRepositoriesResult) -> SlabTree<TreeEnt
     let mut info_map: HashMap<String, HashMap<usize, Vec<APTRepositoryInfo>>> = HashMap::new();
 
     for info in &config.infos {
-        let inner = info_map.entry(info.path.clone()).or_insert(HashMap::new());
-        let entry = inner.entry(info.index).or_insert(Vec::new());
+        let inner = info_map.entry(info.path.clone()).or_default();
+        let entry = inner.entry(info.index).or_default();
         entry.push(info.clone());
     }
 
diff --git a/src/configuration/network_edit.rs b/src/configuration/network_edit.rs
index 010dc30..cf1bc60 100644
--- a/src/configuration/network_edit.rs
+++ b/src/configuration/network_edit.rs
@@ -184,7 +184,7 @@ fn render_bond_form(form_ctx: FormContext, props: &NetworkEdit) -> Html {
         .get_field_value("bond_mode")
         .map(|v| v.as_str().map(String::from))
         .flatten()
-        .unwrap_or(String::new());
+        .unwrap_or_default();
 
     let allow_xmit_hash_policy = mode == "balance-xor" || mode == "802.3ad";
 
diff --git a/src/configuration/network_view.rs b/src/configuration/network_view.rs
index 4666b64..5dd0acf 100644
--- a/src/configuration/network_view.rs
+++ b/src/configuration/network_view.rs
@@ -333,12 +333,12 @@ fn format_ports_slaves(interface: &Interface) -> String {
             .bridge_ports
             .as_ref()
             .map(|ports| ports.join(" "))
-            .unwrap_or(String::new()),
+            .unwrap_or_default(),
         NetworkInterfaceType::Bond => interface
             .slaves
             .as_ref()
             .map(|ports| ports.join(" "))
-            .unwrap_or(String::new()),
+            .unwrap_or_default(),
         NetworkInterfaceType::Alias
         | NetworkInterfaceType::Vlan
         | NetworkInterfaceType::Eth
@@ -500,7 +500,7 @@ fn columns() -> Rc<Vec<DataTableHeader<Interface>>> {
         DataTableColumn::new("Comment")
             .flex(1)
             .render(|item: &Interface| html!{
-                item.comments.clone().unwrap_or(String::new())
+                item.comments.clone().unwrap_or_default()
             })
             .into()
 
-- 
2.39.5





More information about the pdm-devel mailing list