From 18e4fef62f9b3ef76eaf04cd18279fe4bb6f6680 Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 28 Aug 2023 20:03:13 -0400 Subject: [PATCH] Improve help output --- src/value/table.rs | 16 +++++++++++++++- src/value/value_type.rs | 28 +++++++++++++++++++--------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/value/table.rs b/src/value/table.rs index 65bf261..9dee03b 100644 --- a/src/value/table.rs +++ b/src/value/table.rs @@ -162,7 +162,21 @@ impl Display for Table { for row in &self.rows { let row = row.iter().map(|value| { let text = match value { - Value::List(list) => format!("{list:?}"), + Value::List(list) => { + let mut string = "(".to_string(); + + for (index, value) in list.into_iter().enumerate() { + if index > 0 { + string.push_str(", "); + } + + string.push_str(&value.to_string()); + } + + string.push_str(")"); + + string + } Value::Map(map) => format!("Map ({} items)", map.len()), Value::Table(table) => format!("Table ({} items)", table.len()), Value::Function(_) => "Function".to_string(), diff --git a/src/value/value_type.rs b/src/value/value_type.rs index 3b0a53d..fc0c359 100644 --- a/src/value/value_type.rs +++ b/src/value/value_type.rs @@ -1,9 +1,9 @@ -use std::fmt::Display; +use std::fmt::{self, Debug, Display, Formatter}; use crate::Value; /// The type of a `Value`. -#[derive(Clone, Debug)] +#[derive(Clone)] pub enum ValueType { Any, String, @@ -53,7 +53,7 @@ impl PartialEq for ValueType { } impl Display for ValueType { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match &self { ValueType::Any => write!(f, "any"), ValueType::String => write!(f, "string"), @@ -62,15 +62,19 @@ impl Display for ValueType { ValueType::Boolean => write!(f, "boolean"), ValueType::List => write!(f, "list"), ValueType::ListOf(value_type) => { - write!(f, "list of {value_type}") + write!(f, "({value_type}s)") } ValueType::ListExact(list) => { - let items = list - .iter() - .map(|value_type| value_type.to_string() + " ") - .collect::(); + write!(f, "(")?; + for (index, item) in list.into_iter().enumerate() { + if index > 0 { + write!(f, ", ")?; + } - write!(f, "list of {items}") + write!(f, "{item}")?; + } + + write!(f, ")") } ValueType::Empty => write!(f, "empty"), ValueType::Map => write!(f, "map"), @@ -81,6 +85,12 @@ impl Display for ValueType { } } +impl Debug for ValueType { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!(f, "{self}") + } +} + impl From<&Value> for ValueType { fn from(value: &Value) -> Self { match value {