-
-
Save nomissbowling/9a0b76fca4f708528c5571ea301617ea to your computer and use it in GitHub Desktop.
Display Numeric Vector [Rust]
This file contains hidden or 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