Improve help output
This commit is contained in:
parent
1f10bde1b4
commit
18e4fef62f
@ -162,7 +162,21 @@ impl Display for Table {
|
|||||||
for row in &self.rows {
|
for row in &self.rows {
|
||||||
let row = row.iter().map(|value| {
|
let row = row.iter().map(|value| {
|
||||||
let text = match 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::Map(map) => format!("Map ({} items)", map.len()),
|
||||||
Value::Table(table) => format!("Table ({} items)", table.len()),
|
Value::Table(table) => format!("Table ({} items)", table.len()),
|
||||||
Value::Function(_) => "Function".to_string(),
|
Value::Function(_) => "Function".to_string(),
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use std::fmt::Display;
|
use std::fmt::{self, Debug, Display, Formatter};
|
||||||
|
|
||||||
use crate::Value;
|
use crate::Value;
|
||||||
|
|
||||||
/// The type of a `Value`.
|
/// The type of a `Value`.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub enum ValueType {
|
pub enum ValueType {
|
||||||
Any,
|
Any,
|
||||||
String,
|
String,
|
||||||
@ -53,7 +53,7 @@ impl PartialEq for ValueType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Display 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 {
|
match &self {
|
||||||
ValueType::Any => write!(f, "any"),
|
ValueType::Any => write!(f, "any"),
|
||||||
ValueType::String => write!(f, "string"),
|
ValueType::String => write!(f, "string"),
|
||||||
@ -62,15 +62,19 @@ impl Display for ValueType {
|
|||||||
ValueType::Boolean => write!(f, "boolean"),
|
ValueType::Boolean => write!(f, "boolean"),
|
||||||
ValueType::List => write!(f, "list"),
|
ValueType::List => write!(f, "list"),
|
||||||
ValueType::ListOf(value_type) => {
|
ValueType::ListOf(value_type) => {
|
||||||
write!(f, "list of {value_type}")
|
write!(f, "({value_type}s)")
|
||||||
}
|
}
|
||||||
ValueType::ListExact(list) => {
|
ValueType::ListExact(list) => {
|
||||||
let items = list
|
write!(f, "(")?;
|
||||||
.iter()
|
for (index, item) in list.into_iter().enumerate() {
|
||||||
.map(|value_type| value_type.to_string() + " ")
|
if index > 0 {
|
||||||
.collect::<String>();
|
write!(f, ", ")?;
|
||||||
|
}
|
||||||
|
|
||||||
write!(f, "list of {items}")
|
write!(f, "{item}")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
write!(f, ")")
|
||||||
}
|
}
|
||||||
ValueType::Empty => write!(f, "empty"),
|
ValueType::Empty => write!(f, "empty"),
|
||||||
ValueType::Map => write!(f, "map"),
|
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 {
|
impl From<&Value> for ValueType {
|
||||||
fn from(value: &Value) -> Self {
|
fn from(value: &Value) -> Self {
|
||||||
match value {
|
match value {
|
||||||
|
Loading…
Reference in New Issue
Block a user