]> git.scottworley.com Git - tablify/blobdiff - src/lib.rs
Appease clippy::impl_trait_in_params
[tablify] / src / lib.rs
index 4deceffb5ff53677903e6f4e2a46a93d7390a462..ac52b1fb61f184ae0f7c4dd48592e832311e52a5 100644 (file)
@@ -50,6 +50,16 @@ impl Config {
                     .substitute_labels
                     .insert(col.to_owned(), label.to_owned()),
             };
+        } else if let Some(directive) = cmd.strip_prefix("mark ") {
+            match directive.split_once(':') {
+                None => {
+                    return Err(std::io::Error::new(
+                        std::io::ErrorKind::InvalidInput,
+                        format!("line {line_num}: Mark missing ':'"),
+                    ))
+                }
+                Some((col, label)) => self.mark.insert(col.to_owned(), label.to_owned()),
+            };
         } else {
             return Err(std::io::Error::new(
                 std::io::ErrorKind::InvalidInput,
@@ -197,9 +207,7 @@ impl<'cfg, Input: Iterator<Item = Result<String, std::io::Error>>> Reader<'cfg,
         }
     }
 }
-impl<'cfg, Input: Iterator<Item = Result<String, std::io::Error>>> Iterator
-    for Reader<'cfg, Input>
-{
+impl<Input: Iterator<Item = Result<String, std::io::Error>>> Iterator for Reader<'_, Input> {
     type Item = Result<Rowlike, std::io::Error>;
     fn next(&mut self) -> Option<Self::Item> {
         loop {
@@ -413,7 +421,7 @@ fn column_header_labels<'a>(
     let dynamic_columns = columns.iter().map(Some);
     static_columns
         .chain(dynamic_columns)
-        .filter(|ocol| ocol.map_or(true, |col| !config.hidden_columns.contains(col)))
+        .filter(|ocol| ocol.is_none_or(|col| !config.hidden_columns.contains(col)))
         .map(|ocol| {
             ocol.map(|col| match config.substitute_labels.get(col) {
                 None => col,
@@ -449,7 +457,7 @@ fn render_column_headers(config: &Config, columns: &[String]) -> HTML {
 ///   * there's an i/o error while reading `input`
 ///   * the log has invalid syntax:
 ///     * an indented line with no preceding non-indented line
-pub fn tablify(input: impl std::io::Read) -> Result<HTML, std::io::Error> {
+pub fn tablify<R: std::io::Read>(input: R) -> Result<HTML, std::io::Error> {
     let (rows, config) = read_input(input)?;
     let columns = column_order(&config, &rows);
     Ok(HTML(format!(
@@ -641,6 +649,7 @@ mod tests {
                 .substitute_labels["foo"],
             "bar"
         );
+        assert_eq!(read_config(&b"!mark foo:*"[..]).unwrap().mark["foo"], "*");
 
         let bad_command = read_config(&b"!no such command"[..]);
         assert!(bad_command.is_err());
@@ -653,6 +662,10 @@ mod tests {
         let bad_sub = read_config(&b"!label foo"[..]);
         assert!(bad_sub.is_err());
         assert!(format!("{bad_sub:?}").contains("line 1: Annotation missing ':'"));
+
+        let bad_mark = read_config(&b"!mark foo"[..]);
+        assert!(bad_mark.is_err());
+        assert!(format!("{bad_mark:?}").contains("line 1: Mark missing ':'"));
     }
 
     #[test]