2021-09-10 15:00:40 +00:00
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
struct List(Vec<i32>);
|
|
|
|
|
|
|
|
impl fmt::Display for List {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let vec = &self.0;
|
|
|
|
|
|
|
|
write!(f, "[")?;
|
|
|
|
|
2021-09-10 15:01:45 +00:00
|
|
|
for (count, v) in vec.iter().enumerate() {
|
|
|
|
if count != 0 {
|
|
|
|
write!(f, ", ")?;
|
|
|
|
}
|
|
|
|
write!(f, "{}: {}", count, v)?;
|
2021-09-10 15:00:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
write!(f, "]")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let v = List(vec![1, 2, 3]);
|
|
|
|
println!("{}", v);
|
|
|
|
}
|