You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
495 B
26 lines
495 B
3 years ago
|
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, "[")?;
|
||
|
|
||
3 years ago
|
for (count, v) in vec.iter().enumerate() {
|
||
|
if count != 0 {
|
||
|
write!(f, ", ")?;
|
||
|
}
|
||
|
write!(f, "{}: {}", count, v)?;
|
||
3 years ago
|
}
|
||
|
|
||
|
write!(f, "]")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
1 year ago
|
let v = List(vec![6, 0, 6, 8, 0, 8, 9, 1, 1, 1, 3, 1, 2]);
|
||
3 years ago
|
println!("{}", v);
|
||
|
}
|