simplify option_vec_printer

This commit is contained in:
Simon Gardling 2022-03-24 18:16:33 -04:00
parent 484267c1a4
commit d97c149e1f

View File

@ -248,25 +248,25 @@ where
T: Clone, T: Clone,
{ {
let max_i: i32 = (data.len() as i32) - 1; let max_i: i32 = (data.len() as i32) - 1;
let output: String = data "[".to_owned()
.iter() + &data
.enumerate() .iter()
.map(|(i, x)| { .enumerate()
let mut tmp = match x { .map(|(i, x)| {
Some(inner) => inner.to_string(), let mut tmp = match x {
_ => "None".to_string(), Some(inner) => inner.to_string(),
}; _ => "None".to_string(),
};
// Add comma and space if needed // Add comma and space if needed
if max_i > i as i32 { if max_i > i as i32 {
tmp += ", "; tmp += ", ";
} }
tmp tmp
}) })
.collect::<Vec<String>>() .collect::<Vec<String>>()
.concat(); .concat()
+ "]"
format!("[{}]", output)
} }
// Returns a vector of length `max_i` starting at value `min_x` with resolution // Returns a vector of length `max_i` starting at value `min_x` with resolution
// of `resolution` // of `resolution`