]> git.scottworley.com Git - tablify/commitdiff
extract render_instances()
authorScott Worley <scottworley@scottworley.com>
Thu, 26 Sep 2024 01:16:23 +0000 (18:16 -0700)
committerScott Worley <scottworley@scottworley.com>
Wed, 2 Oct 2024 09:40:47 +0000 (02:40 -0700)
src/lib.rs

index f1da5f7270cb2a285df10bbffca9ba1da061c720..1396c9be9b9605d18af6efce8deb974b121e6408 100644 (file)
@@ -194,29 +194,32 @@ fn render_one_instance(instance: &Option<String>) -> HTML {
     }
 }
 
     }
 }
 
-fn render_cell(col: &str, row: &mut Row) -> HTML {
-    let row_label = HTML::escape(row.label.as_ref());
-    let col_label = HTML::escape(col);
-    let instances: Option<&Vec<Option<String>>> = row.entries.get(col);
-    let class = HTML::from(if instances.is_none() { "" } else { "yes" });
-    let all_empty = instances
-        .iter()
-        .flat_map(|is| is.iter())
-        .all(Option::is_none);
-    let contents = if instances.is_none() || (all_empty && instances.unwrap().len() == 1) {
+fn render_instances(instances: &[Option<String>]) -> HTML {
+    let all_empty = instances.iter().all(Option::is_none);
+    if all_empty && instances.len() == 1 {
         HTML::from("")
     } else if all_empty {
         HTML::from("")
     } else if all_empty {
-        HTML(format!("{}", instances.unwrap().len()))
+        HTML(format!("{}", instances.len()))
     } else {
         HTML(
             instances
     } else {
         HTML(
             instances
-                .unwrap()
                 .iter()
                 .map(render_one_instance)
                 .map(|html| html.0) // Waiting for slice_concat_trait to stabilize
                 .collect::<Vec<_>>()
                 .join(" "),
         )
                 .iter()
                 .map(render_one_instance)
                 .map(|html| html.0) // Waiting for slice_concat_trait to stabilize
                 .collect::<Vec<_>>()
                 .join(" "),
         )
+    }
+}
+
+fn render_cell(col: &str, row: &mut Row) -> HTML {
+    let row_label = HTML::escape(row.label.as_ref());
+    let col_label = HTML::escape(col);
+    let instances: Option<&Vec<Option<String>>> = row.entries.get(col);
+    let class = HTML::from(if instances.is_none() { "" } else { "yes" });
+    let contents = match instances {
+        None => HTML::from(""),
+        Some(is) => render_instances(is),
     };
     row.entries.remove(col);
     HTML(format!(
     };
     row.entries.remove(col);
     HTML(format!(