1
0

Improve list display

This commit is contained in:
Jeff 2024-01-01 10:09:11 -05:00
parent 799875a55d
commit a8ed942c13
2 changed files with 20 additions and 7 deletions

View File

@ -1,5 +1,6 @@
use std::{
cmp::Ordering,
fmt::{self, Display, Formatter},
sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard},
};
@ -61,3 +62,21 @@ impl PartialOrd for List {
Some(self.cmp(other))
}
}
impl Display for List {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let items = self.items();
write!(f, "[")?;
for (index, value) in items.iter().enumerate() {
write!(f, "{value}")?;
if index != items.len() - 1 {
write!(f, ", ")?;
}
}
write!(f, "]")
}
}

View File

@ -489,13 +489,7 @@ impl Display for Value {
write!(f, "none")
}
}
Value::List(list) => {
write!(f, "[")?;
for value in list.items().iter() {
write!(f, " {value} ")?;
}
write!(f, "]")
}
Value::List(list) => write!(f, "{list}"),
Value::Map(map) => write!(f, "{map}"),
Value::Function(function) => write!(f, "{function}"),
}