Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created August 10, 2017 06:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save whatalnk/f308517fe2c497790b6ee8fcb34488ba to your computer and use it in GitHub Desktop.
Save whatalnk/f308517fe2c497790b6ee8fcb34488ba to your computer and use it in GitHub Desktop.
Display Numeric Vector [Rust]
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