microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
source/compiler/qsc_data_structures/src/display.rs
20lines · modeblame
444dea81César Zaragoza Cortés2 years ago | 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. | |
| 3 | | |
| 4 | use std::fmt::{self, Display, Formatter}; | |
| 5 | | |
| 6 | /// Displays values separated by the provided string. | |
| 7 | pub fn join( | |
| 8 | f: &mut Formatter, | |
| 9 | mut vals: impl Iterator<Item = impl Display>, | |
| 10 | sep: &str, | |
| 11 | ) -> fmt::Result { | |
| 12 | if let Some(v) = vals.next() { | |
| 13 | v.fmt(f)?; | |
| 14 | } | |
| 15 | for v in vals { | |
| 16 | write!(f, "{sep}")?; | |
| 17 | v.fmt(f)?; | |
| 18 | } | |
| 19 | Ok(()) | |
| 20 | } |