Through 1.2.2.1
This commit is contained in:
parent
de02f07049
commit
963fe0a864
4
rustbyexample/01221/Cargo.lock
generated
Normal file
4
rustbyexample/01221/Cargo.lock
generated
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[root]
|
||||||
|
name = "01221"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
6
rustbyexample/01221/Cargo.toml
Normal file
6
rustbyexample/01221/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "01221"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Dan Buch <daniel.buch@gmail.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user