Skip to content

Instantly share code, notes, and snippets.

@nomissbowling
Forked from whatalnk/display_vec.rs
Created March 1, 2024 05:49
Show Gist options
  • Save nomissbowling/9a0b76fca4f708528c5571ea301617ea to your computer and use it in GitHub Desktop.
Save nomissbowling/9a0b76fca4f708528c5571ea301617ea 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