MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / separated

Function separated

src/ore/src/str.rs:193–224  ·  view source on GitHub ↗

Creates a type whose [`fmt::Display`] implementation outputs each item in `iter` separated by `separator`.

(separator: &'a str, iter: I)

Source from the content-addressed store, hash-verified

191/// Creates a type whose [`fmt::Display`] implementation outputs each item in
192/// `iter` separated by `separator`.
193pub fn separated<'a, I>(separator: &'a str, iter: I) -> impl fmt::Display + 'a
194where
195 I: IntoIterator,
196 I::IntoIter: Clone + 'a,
197 I::Item: fmt::Display + 'a,
198{
199 struct Separated<'a, I> {
200 separator: &'a str,
201 iter: I,
202 }
203
204 impl<'a, I> fmt::Display for Separated<'a, I>
205 where
206 I: Iterator + Clone,
207 I::Item: fmt::Display,
208 {
209 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
210 for (i, item) in self.iter.clone().enumerate() {
211 if i != 0 {
212 write!(f, "{}", self.separator)?;
213 }
214 write!(f, "{}", item)?;
215 }
216 Ok(())
217 }
218 }
219
220 Separated {
221 separator,
222 iter: iter.into_iter(),
223 }
224}
225
226/// A helper struct to keep track of indentation levels.
227///

Callers 15

display_import_idsMethod · 0.50
display_export_idsMethod · 0.50
fmt_default_textMethod · 0.50
fmt_verbose_textMethod · 0.50
fmt_textMethod · 0.50
fmtMethod · 0.50
fmt_textMethod · 0.50
fmt_default_textMethod · 0.50
fmt_verbose_syntaxMethod · 0.50
humanizeMethod · 0.50
from_json_fieldsFunction · 0.50
fmtMethod · 0.50

Calls 1

into_iterMethod · 0.45

Tested by

no test coverage detected