Skip to content

Commit d792430

Browse files
committed
Small refactor in 'format_pretty'
1 parent 025242f commit d792430

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

src/main.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ extern crate clap;
22
extern crate pad;
33

44
mod config;
5-
65
use pad::PadStr;
76
use std::io::{self, Result, BufRead, BufReader};
87
use std::fs::{self, File};
@@ -66,26 +65,23 @@ fn format_pretty(data: &Vec<Vec<String>>) -> String {
6665
.map(|(s,len)| max(s.len(), len))
6766
.collect()
6867
);
69-
let format_row = |row: &Vec<String>| row.iter()
70-
.zip(&lengths)
71-
.map(|(s, len)| s.pad_to_width(*len))
72-
.collect::<Vec<_>>()
73-
.join(" | ");
7468

75-
let header = format_row(&data[0]);
69+
let rows = data.iter()
70+
.map(|row| row.iter()
71+
.zip(&lengths)
72+
.map(|(s, len)| s.pad_to_width(*len))
73+
.collect::<Vec<_>>()
74+
.join(" | ")
75+
)
76+
.collect::<Vec<_>>();
7677
let separator = lengths.iter()
7778
.map(|len| "-".repeat(*len))
7879
.collect::<Vec<_>>()
7980
.join("-|-");
80-
let rows = data[1..].iter()
81-
.map(format_row)
82-
.collect::<Vec<_>>()
83-
.join(" |\n| ");
84-
8581
[
86-
format!("| {} |", header),
82+
format!("| {} |", rows[0]),
8783
format!("|-{}-|", separator),
88-
format!("| {} |", rows),
84+
format!("| {} |", rows[1..].join(" |\n| ")),
8985
].join("\n")
9086
}
9187

0 commit comments

Comments
 (0)