Through 1.2.2.1
This commit is contained in:
23
rustbyexample/01221/src/main.rs
Normal file
23
rustbyexample/01221/src/main.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use std::fmt;
|
||||
|
||||
struct List(Vec<i32>);
|
||||
|
||||
impl fmt::Display for List {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let List(ref vec) = *self;
|
||||
|
||||
try!(write!(f, "["));
|
||||
|
||||
for (count, v) in vec.iter().enumerate() {
|
||||
if count != 0 { try!(write!(f, ", ")); }
|
||||
try!(write!(f, "{}", v));
|
||||
}
|
||||
|
||||
write!(f, "]")
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let v = List(vec![1, 2, 3]);
|
||||
println!("{}", v);
|
||||
}
|
Reference in New Issue
Block a user