git.delta.rocks / jrsonnet / refs/commits / 0ef9787dd3a6

difftreelog

fix ToStringFormat should not quote top-level string

Yaroslav Bolyukin2024-06-18parent: #12a8bf0.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-evaluator/src/manifest.rsdiffbeforeafterboth
84 debug_truncate_strings: None,84 debug_truncate_strings: None,
85 }85 }
86 }86 }
87 // Same format as std.toString87 /// Same format as std.toString, except does not keeps top-level string as-is
88 /// To avoid confusion, the format is private in jrsonnet, use [`ToStringFormat`] instead
88 pub fn std_to_string() -> Self {89 const fn std_to_string_helper() -> Self {
89 Self {90 Self {
90 padding: Cow::Borrowed(""),91 padding: Cow::Borrowed(""),
91 mtype: JsonFormatting::ToString,92 mtype: JsonFormatting::ToString,
344 }345 }
345}346}
346347
348/// Same as [`JsonFormat`] with pre-set options, but top-level string is serialized as-is,
349/// without quoting.
347pub struct ToStringFormat;350pub struct ToStringFormat;
348impl ManifestFormat for ToStringFormat {351impl ManifestFormat for ToStringFormat {
349 fn manifest_buf(&self, val: Val, out: &mut String) -> Result<()> {352 fn manifest_buf(&self, val: Val, out: &mut String) -> Result<()> {
350 JsonFormat::std_to_string().manifest_buf(val, out)353 const JSON_TO_STRING: JsonFormat = JsonFormat::std_to_string_helper();
354 if let Some(str) = val.as_str() {
355 out.push_str(&str);
356 return Ok(());
357 }
358 JSON_TO_STRING.manifest_buf(val, out)
351 }359 }
352 fn file_trailing_newline(&self) -> bool {360 fn file_trailing_newline(&self) -> bool {
353 false361 false
modifiedcrates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth
132 Optional,132 Optional,
133 Default(Expr),133 Default(Expr),
134}134}
135impl Optionality {
136 fn is_optional(&self) -> bool {
137 !matches!(self, Self::Required)
138 }
139}
140135
141enum ArgInfo {136enum ArgInfo {
142 Normal {137 Normal {