Created
August 10, 2017 06:13
-
-
Save whatalnk/f308517fe2c497790b6ee8fcb34488ba to your computer and use it in GitHub Desktop.
Display Numeric Vector [Rust]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fmt; | |
struct Array(Vec<i64>); | |
impl fmt::Display for Array { | |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
let Array(ref vec) = *self; | |
for (count, v) in vec.iter().enumerate() { | |
if count != 0 { try!(write!(f, " ")); } | |
try!(write!(f, "{}", v)); | |
} | |
write!(f, "\n") | |
} | |
} | |
fn main() { | |
let arr = vec![1,2,3,4,5,6,7,8,9,10]; | |
print!("{}", Array(arr)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment