1
use std::fmt;
2

            
3
/// Utility to print a repeated static string a given number of times.
4
pub struct Repeat {
5
    s: &'static str,
6
    times: usize,
7
}
8

            
9
impl Repeat {
10
    /// Creates a new Repeat instance.
11
6919
    pub fn new(s: &'static str, times: usize) -> Self {
12
6919
        Self { s, times }
13
6919
    }
14
}
15

            
16
impl fmt::Display for Repeat {
17
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18
        for _ in 0..self.times {
19
            f.write_str(self.s)?;
20
        }
21
        Ok(())
22
    }
23
}