git.delta.rocks / jrsonnet / refs/commits / 11dc48e90ac0

difftreelog

fix experimental build

Yaroslav Bolyukin2024-05-01parent: #f0883bb.patch.diff
in: master

4 files changed

modifiedcrates/jrsonnet-evaluator/src/evaluate/destructure.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
@@ -110,10 +110,7 @@
 						fn get(self: Box<Self>) -> Result<Self::Output> {
 							let full = self.full.evaluate()?;
 							let to = full.len() - self.end;
-							Ok(Val::Arr(
-								full.slice(Some(self.start), Some(to), None)
-									.expect("arguments checked"),
-							))
+							Ok(Val::Arr(full.slice(Some(self.start as i32), Some(to as i32), None)))
 						}
 					}
 
modifiedcrates/jrsonnet-stdlib/src/manifest/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/manifest/mod.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/mod.rs
@@ -10,8 +10,8 @@
 };
 pub use python::{PythonFormat, PythonVarsFormat};
 pub use toml::TomlFormat;
+pub use xml::XmlJsonmlFormat;
 pub use yaml::YamlFormat;
-pub use xml::XmlJsonmlFormat;
 
 #[builtin]
 pub fn builtin_escape_string_json(str_: IStr) -> Result<String> {
@@ -150,12 +150,30 @@
 }
 
 #[builtin]
-pub fn builtin_manifest_python(v: Val) -> Result<String> {
-	v.manifest(PythonFormat {})
+pub fn builtin_manifest_python(
+	v: Val,
+
+	#[default(false)]
+	#[cfg(feature = "exp-preserve-order")]
+	preserve_order: bool,
+) -> Result<String> {
+	v.manifest(PythonFormat::std(
+		#[cfg(feature = "exp-preserve-order")]
+		preserve_order,
+	))
 }
 #[builtin]
-pub fn builtin_manifest_python_vars(v: Val) -> Result<String> {
-	v.manifest(PythonVarsFormat {})
+pub fn builtin_manifest_python_vars(
+	v: Val,
+
+	#[default(false)]
+	#[cfg(feature = "exp-preserve-order")]
+	preserve_order: bool,
+) -> Result<String> {
+	v.manifest(PythonVarsFormat::std(
+		#[cfg(feature = "exp-preserve-order")]
+		preserve_order,
+	))
 }
 
 #[builtin]
modifiedcrates/jrsonnet-stdlib/src/manifest/python.rsdiffbeforeafterboth
before · crates/jrsonnet-stdlib/src/manifest/python.rs
1use jrsonnet_evaluator::{2	bail,3	manifest::{escape_string_json_buf, ManifestFormat, ToStringFormat},4	Result, Val,5};67pub struct PythonFormat {8	#[cfg(feature = "exp-preserve-order")]9	preserve_order: bool,10}1112impl ManifestFormat for PythonFormat {13	fn manifest_buf(&self, val: Val, buf: &mut String) -> Result<()> {14		match val {15			Val::Bool(true) => buf.push_str("True"),16			Val::Bool(false) => buf.push_str("False"),17			Val::Null => buf.push_str("None"),18			Val::Str(s) => escape_string_json_buf(&s.to_string(), buf),19			Val::Num(_) => ToStringFormat.manifest_buf(val, buf)?,20			Val::Arr(arr) => {21				buf.push('[');22				for (i, el) in arr.iter().enumerate() {23					let el = el?;24					if i != 0 {25						buf.push_str(", ");26					}27					self.manifest_buf(el, buf)?;28				}29				buf.push(']');30			}31			Val::Obj(obj) => {32				obj.run_assertions()?;33				buf.push('{');34				let fields = obj.fields(35					#[cfg(feature = "exp-preserve-order")]36					self.preserve_order,37				);38				for (i, field) in fields.into_iter().enumerate() {39					if i != 0 {40						buf.push_str(", ");41					}42					escape_string_json_buf(&field, buf);43					buf.push_str(": ");44					let value = obj.get(field)?.expect("field exists");45					self.manifest_buf(value, buf)?;46				}47				buf.push('}');48			}49			Val::Func(_) => bail!("tried to manifest function"),50		}51		Ok(())52	}53}5455pub struct PythonVarsFormat {56	#[cfg(feature = "exp-preserve-order")]57	preserve_order: bool,58}5960impl PythonVarsFormat {}6162impl ManifestFormat for PythonVarsFormat {63	fn manifest_buf(&self, val: Val, buf: &mut String) -> Result<()> {64		let inner = PythonFormat {65			#[cfg(feature = "exp-preserve-order")]66			preserve_order: self.preserve_order,67		};68		let Val::Obj(obj) = val else {69			bail!("python vars root should be object");70		};71		obj.run_assertions()?;7273		let fields = obj.fields(74			#[cfg(feature = "exp-preserve-order")]75			self.preserve_order,76		);7778		for field in fields {79			// Yep, no escaping80			buf.push_str(&field);81			buf.push_str(" = ");82			inner.manifest_buf(obj.get(field)?.expect("field exists"), buf)?;83			buf.push('\n');84		}85		Ok(())86	}87}
after · crates/jrsonnet-stdlib/src/manifest/python.rs
1use jrsonnet_evaluator::{2	bail,3	manifest::{escape_string_json_buf, ManifestFormat, ToStringFormat},4	Result, Val,5};67pub struct PythonFormat {8	#[cfg(feature = "exp-preserve-order")]9	preserve_order: bool,10}1112impl PythonFormat {13	pub fn std(#[cfg(feature = "exp-preserve-order")] preserve_order: bool) -> Self {14		Self {15			#[cfg(feature = "exp-preserve-order")]16			preserve_order,17		}18	}19}2021impl ManifestFormat for PythonFormat {22	fn manifest_buf(&self, val: Val, buf: &mut String) -> Result<()> {23		match val {24			Val::Bool(true) => buf.push_str("True"),25			Val::Bool(false) => buf.push_str("False"),26			Val::Null => buf.push_str("None"),27			Val::Str(s) => escape_string_json_buf(&s.to_string(), buf),28			Val::Num(_) => ToStringFormat.manifest_buf(val, buf)?,29			#[cfg(feature = "exp-bigint")]30			Val::BigInt(_) => ToStringFormat.manifest_buf(val, buf)?,31			Val::Arr(arr) => {32				buf.push('[');33				for (i, el) in arr.iter().enumerate() {34					let el = el?;35					if i != 0 {36						buf.push_str(", ");37					}38					self.manifest_buf(el, buf)?;39				}40				buf.push(']');41			}42			Val::Obj(obj) => {43				obj.run_assertions()?;44				buf.push('{');45				let fields = obj.fields(46					#[cfg(feature = "exp-preserve-order")]47					self.preserve_order,48				);49				for (i, field) in fields.into_iter().enumerate() {50					if i != 0 {51						buf.push_str(", ");52					}53					escape_string_json_buf(&field, buf);54					buf.push_str(": ");55					let value = obj.get(field)?.expect("field exists");56					self.manifest_buf(value, buf)?;57				}58				buf.push('}');59			}60			Val::Func(_) => bail!("tried to manifest function"),61		}62		Ok(())63	}64}6566pub struct PythonVarsFormat {67	#[cfg(feature = "exp-preserve-order")]68	preserve_order: bool,69}7071impl PythonVarsFormat {72	pub fn std(#[cfg(feature = "exp-preserve-order")] preserve_order: bool) -> Self {73		Self {74			#[cfg(feature = "exp-preserve-order")]75			preserve_order,76		}77	}78}7980impl ManifestFormat for PythonVarsFormat {81	fn manifest_buf(&self, val: Val, buf: &mut String) -> Result<()> {82		let inner = PythonFormat {83			#[cfg(feature = "exp-preserve-order")]84			preserve_order: self.preserve_order,85		};86		let Val::Obj(obj) = val else {87			bail!("python vars root should be object");88		};89		obj.run_assertions()?;9091		let fields = obj.fields(92			#[cfg(feature = "exp-preserve-order")]93			self.preserve_order,94		);9596		for field in fields {97			// Yep, no escaping98			buf.push_str(&field);99			buf.push_str(" = ");100			inner.manifest_buf(obj.get(field)?.expect("field exists"), buf)?;101			buf.push('\n');102		}103		Ok(())104	}105}
modifiedcrates/jrsonnet-stdlib/src/manifest/xml.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/manifest/xml.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/xml.rs
@@ -95,7 +95,11 @@
 			buf.push('<');
 			buf.push_str(&tag);
 			attrs.run_assertions()?;
-			for (key, value) in attrs.iter() {
+			for (key, value) in attrs.iter(
+				// Not much sense to preserve order here
+				#[cfg(feature = "exp-preserve-order")]
+				false,
+			) {
 				buf.push(' ');
 				buf.push_str(&key);
 				buf.push('=');