@@ -16,7 +16,11 @@ pub struct Info {
1616}
1717
1818impl 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+ where
21+ T: AsRef<str>,
22+ U: AsRef<str>,
23+ {
2024 if body.is_empty() {
2125 return Self {
2226 title: title.to_string(),
@@ -26,11 +30,21 @@ impl Info {
2630 };
2731 }
2832
29− let item_width = body.iter().map(|(item, _)| item.width()).max().unwrap();
33+ let item_width = body
34+ .iter()
35+ .map(|(item, _)| item.as_ref().width())
36+ .max()
37+ .unwrap();
3038 let mut text = String::new();
3139
32− for (item, desc) in &body {
33− let _ = writeln!(text, "{:width$} {}", item, desc, width = item_width);
40+ for (item, desc) in body {
41+ let _ = writeln!(
42+ text,
43+ "{:width$} {}",
44+ item.as_ref(),
45+ desc.as_ref(),
46+ width = item_width
47+ );
3448 }
3549
3650 Self {
@@ -42,19 +56,19 @@ impl Info {
4256 }
4357
4458 pub fn from_keymap(title: &str, body: Vec<(&str, BTreeSet<KeyEvent>)>) -> Self {
45− let body = body
59+ let body: Vec<_> = body
4660 .into_iter()
4761 .map(|(desc, events)| {
4862 let events = events.iter().map(ToString::to_string).collect::<Vec<_>>();
49− (events.join(", "), desc.to_string())
63+ (events.join(", "), desc)
5064 })
5165 .collect();
5266
53− Self::new(title, body)
67+ Self::new(title, &body)
5468 }
5569
5670 pub fn from_registers(registers: &Registers) -> Self {
57− let body = registers
71+ let body: Vec<_> = registers
5872 .inner()
5973 .iter()
6074 .map(|(ch, reg)| {
@@ -62,13 +76,12 @@ impl Info {
6276 .read()
6377 .get(0)
6478 .and_then(|s| s.lines().next())
65− .map(String::from)
6679 .unwrap_or_default();
6780 (ch.to_string(), content)
6881 })
6982 .collect();
7083
71− let mut infobox = Self::new("Registers", body);
84+ let mut infobox = Self::new("Registers", &body);
7285 infobox.width = 30; // copied content could be very long
7386 infobox
7487 }