seq_fmt/
lib.rs

1use std::fmt::Display;
2
3pub fn comma<T: Display>(values: &[T]) -> String {
4    match values.len() {
5        0 => String::new(),
6        1 => values[0].to_string(),
7        _ => {
8            let mut result = String::new();
9            for (i, value) in values.iter().enumerate() {
10                if i > 0 {
11                    result.push_str(", ");
12                }
13                result.push_str(&value.to_string());
14            }
15            result
16        }
17    }
18}
19
20pub fn comma_tuple<K: Display, V: Display>(values: &[(K, V)]) -> String {
21    let mut result = String::new();
22    for (i, (key, value)) in values.iter().enumerate() {
23        if i > 0 {
24            result.push_str(", ");
25        }
26        result.push_str(format!("{}: {}", key, value).as_str());
27    }
28    result
29}
30
31pub fn fmt_nl<T: Display>(values: &[T]) -> String {
32    let mut result = String::new();
33    for (i, value) in values.iter().enumerate() {
34        if i > 0 {
35            result.push_str("\n");
36        }
37        result.push_str(&value.to_string());
38    }
39    result
40}