@@ -16,7 +16,11 @@ pub struct Info {
18impl Info {
18impl Info {
19− pub fn new(title: &str, body: Vec<(String, String)>) -> Self {
19+ pub fn new<T, U>(title: &str, body: &[(T, U)]) -> Self
20 if body.is_empty() {
24 if body.is_empty() {
21 return Self {
25 return Self {
22 title: title.to_string(),
26 title: title.to_string(),
@@ -26,11 +30,21 @@ impl Info {
29− let item_width = body.iter().map(|(item, _)| item.width()).max().unwrap();
33+ let item_width = body
35+ .map(|(item, _)| item.as_ref().width())
30 let mut text = String::new();
38 let mut text = String::new();
32− for (item, desc) in &body {
40+ for (item, desc) in body {
33− let _ = writeln!(text, "{:width$} {}", item, desc, width = item_width);
46+ width = item_width
@@ -42,19 +56,19 @@ impl Info {
44 pub fn from_keymap(title: &str, body: Vec<(&str, BTreeSet<KeyEvent>)>) -> Self {
58 pub fn from_keymap(title: &str, body: Vec<(&str, BTreeSet<KeyEvent>)>) -> Self {
45− let body = body
59+ let body: Vec<_> = body
46 .into_iter()
60 .into_iter()
47 .map(|(desc, events)| {
61 .map(|(desc, events)| {
48 let events = events.iter().map(ToString::to_string).collect::<Vec<_>>();
62 let events = events.iter().map(ToString::to_string).collect::<Vec<_>>();
49− (events.join(", "), desc.to_string())
63+ (events.join(", "), desc)
51 .collect();
65 .collect();
53− Self::new(title, body)
67+ Self::new(title, &body)
56 pub fn from_registers(registers: &Registers) -> Self {
70 pub fn from_registers(registers: &Registers) -> Self {
57− let body = registers
71+ let body: Vec<_> = registers
60 .map(|(ch, reg)| {
74 .map(|(ch, reg)| {
@@ -62,13 +76,12 @@ impl Info {
64 .and_then(|s| s.lines().next())
78 .and_then(|s| s.lines().next())
66 .unwrap_or_default();
79 .unwrap_or_default();
67 (ch.to_string(), content)
80 (ch.to_string(), content)
69 .collect();
82 .collect();
71− let mut infobox = Self::new("Registers", body);
84+ let mut infobox = Self::new("Registers", &body);
72 infobox.width = 30; // copied content could be very long
85 infobox.width = 30; // copied content could be very long