Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,22 @@ pub enum Value {
impl fmt::Display for Value {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::String(val) => write!(f, "value string: {}", val.clone()),
Self::Number(val) => write!(f, "value number: {}", val.clone()),
Self::Bool(val) => write!(f, "value bool: {}", val.clone()),
Self::String(val) => write!(f, "value string: {}", val),
Self::Number(val) => write!(f, "value number: {}", val),
Self::Bool(val) => write!(f, "value bool: {}", val),
Self::List(values) => {
let mut s = String::from("[");
write!(f, "value list: [")?;
for value in values {
s.push_str(format!("{},", value.clone()).as_str());
write!(f, "{},", value)?;
}
s.push_str("]");
write!(f, "value list: {}", s)
write!(f, "]")
Comment on lines +24 to +28
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation results in a trailing comma for non-empty lists (e.g., [1,2,3,]). While the PR aims to maintain parity with the previous implementation, this is a good opportunity to improve the output formatting by removing the trailing separator for a more standard representation.

Suggested change
write!(f, "value list: [")?;
for value in values {
s.push_str(format!("{},", value.clone()).as_str());
write!(f, "{},", value)?;
}
s.push_str("]");
write!(f, "value list: {}", s)
write!(f, "]")
write!(f, "value list: [")?;
for (i, value) in values.iter().enumerate() {
if i > 0 {
write!(f, ",")?;
}
write!(f, "{}", value)?;
}
write!(f, "]")

}
Self::Map(m) => {
let mut s = String::from("{");
write!(f, "value map: {{")?;
for (k, v) in m {
s.push_str(format!("key: {},", k.clone()).as_str());
s.push_str(format!("value: {}; ", v.clone()).as_str());
write!(f, "key: {},value: {}; ", k, v)?;
}
s.push_str("}");
write!(f, "value map: {}", s)
write!(f, "}}")
Comment on lines +31 to +35
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the list implementation, the map formatting includes a trailing semicolon and space (e.g., {key: k,value: v; }). Consider refactoring the loop to avoid the trailing separator and ensure a cleaner, more consistent output format.

                write!(f, "value map: {{")?;
                for (i, (k, v)) in m.iter().enumerate() {
                    if i > 0 {
                        write!(f, " ")?;
                    }
                    write!(f, "key: {},value: {};", k, v)?;
                }
                write!(f, "}}")

Comment on lines 23 to +35
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Display output for Value::List/Value::Map is now built via multiple write! calls. Since this is user-visible formatting and can be easy to accidentally change (e.g., trailing commas, braces, separators), please add a unit test that asserts the exact to_string() output for a few representative values (including empty/non-empty list and map) to prevent regressions during future refactors.

Copilot uses AI. Check for mistakes.
}
Self::None => write!(f, "None"),
}
Expand Down
Loading