1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
pub trait Digit<T> {
fn digit(self, d: T) -> String;
}
impl Digit<i32> for i32 {
fn digit(self, d: i32) -> String {
let mut s = self.to_string();
let space = " ".repeat((d as usize) - s.len());
s.push_str(&space);
s
}
}
impl Digit<i32> for String {
fn digit(self, d: i32) -> String {
let mut s = self.clone();
let space = " ".repeat((d as usize) - self.len());
s.push_str(&space);
s
}
}
impl Digit<i32> for &'static str {
fn digit(self, d: i32) -> String {
let mut s = self.to_string();
let space = " ".repeat((d as usize) - self.len());
s.push_str(&space);
s
}
}