Skip to content

Commit 75ec6b9

Browse files
committed
remove generic indented_list implementation
1 parent 4bac835 commit 75ec6b9

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

src/ast/query.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,26 +2883,15 @@ pub struct Values {
28832883

28842884
impl fmt::Display for Values {
28852885
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2886-
struct DisplayRow<'a> {
2887-
exprs: &'a [Expr],
2888-
explicit_row: bool,
2889-
}
2890-
impl fmt::Display for DisplayRow<'_> {
2891-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2892-
let comma_separated = display_comma_separated(self.exprs);
2893-
if self.explicit_row {
2894-
write!(f, "ROW({})", comma_separated)
2895-
} else {
2896-
write!(f, "({})", comma_separated)
2897-
}
2898-
}
2899-
}
2900-
let row_display_iter = self.rows.iter().map(|row| DisplayRow {
2901-
exprs: row,
2902-
explicit_row: self.explicit_row,
2903-
});
29042886
f.write_str("VALUES")?;
2905-
indented_list(f, row_display_iter)?;
2887+
let prefix = if self.explicit_row { "ROW" } else { "" };
2888+
let mut delim = "";
2889+
for row in &self.rows {
2890+
f.write_str(delim)?;
2891+
delim = ",";
2892+
SpaceOrNewline.fmt(f)?;
2893+
Indent(format_args!("{prefix}({})", display_comma_separated(row))).fmt(f)?;
2894+
}
29062895
Ok(())
29072896
}
29082897
}

src/display_utils.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,12 @@ impl Display for SpaceOrNewline {
6868

6969
/// A value that displays a comma-separated list of values.
7070
/// When pretty-printed (using {:#}), it displays each value on a new line.
71-
pub(crate) struct DisplayCommaSeparated<I, T: fmt::Display>(I)
72-
where
73-
I: IntoIterator<Item = T> + Clone;
71+
pub(crate) struct DisplayCommaSeparated<'a, T: fmt::Display>(&'a [T]);
7472

75-
impl<I, T: fmt::Display> fmt::Display for DisplayCommaSeparated<I, T>
76-
where
77-
I: IntoIterator<Item = T> + Clone,
78-
{
73+
impl<T: fmt::Display> fmt::Display for DisplayCommaSeparated<'_, T> {
7974
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8075
let mut first = true;
81-
for t in self.0.clone() {
76+
for t in self.0 {
8277
if !first {
8378
f.write_char(',')?;
8479
SpaceOrNewline.fmt(f)?;
@@ -91,12 +86,9 @@ where
9186
}
9287

9388
/// Displays a whitespace, followed by a comma-separated list that is indented when pretty-printed.
94-
pub(crate) fn indented_list<I, T: fmt::Display>(f: &mut fmt::Formatter, iter: I) -> fmt::Result
95-
where
96-
I: IntoIterator<Item = T> + Clone,
97-
{
89+
pub(crate) fn indented_list<T: fmt::Display>(f: &mut fmt::Formatter, items: &[T]) -> fmt::Result {
9890
SpaceOrNewline.fmt(f)?;
99-
Indent(DisplayCommaSeparated(iter)).fmt(f)
91+
Indent(DisplayCommaSeparated(items)).fmt(f)
10092
}
10193

10294
#[cfg(test)]

0 commit comments

Comments
 (0)