From 11dc48e90ac0f9caf0282dfd09a6c1a4af27ab35 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Wed, 01 May 2024 21:23:19 +0000 Subject: [PATCH] fix: experimental build --- --- a/crates/jrsonnet-evaluator/src/evaluate/destructure.rs +++ b/crates/jrsonnet-evaluator/src/evaluate/destructure.rs @@ -110,10 +110,7 @@ fn get(self: Box) -> Result { 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))) } } --- 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 { @@ -150,12 +150,30 @@ } #[builtin] -pub fn builtin_manifest_python(v: Val) -> Result { - v.manifest(PythonFormat {}) +pub fn builtin_manifest_python( + v: Val, + + #[default(false)] + #[cfg(feature = "exp-preserve-order")] + preserve_order: bool, +) -> Result { + v.manifest(PythonFormat::std( + #[cfg(feature = "exp-preserve-order")] + preserve_order, + )) } #[builtin] -pub fn builtin_manifest_python_vars(v: Val) -> Result { - v.manifest(PythonVarsFormat {}) +pub fn builtin_manifest_python_vars( + v: Val, + + #[default(false)] + #[cfg(feature = "exp-preserve-order")] + preserve_order: bool, +) -> Result { + v.manifest(PythonVarsFormat::std( + #[cfg(feature = "exp-preserve-order")] + preserve_order, + )) } #[builtin] --- a/crates/jrsonnet-stdlib/src/manifest/python.rs +++ b/crates/jrsonnet-stdlib/src/manifest/python.rs @@ -9,6 +9,15 @@ preserve_order: bool, } +impl PythonFormat { + pub fn std(#[cfg(feature = "exp-preserve-order")] preserve_order: bool) -> Self { + Self { + #[cfg(feature = "exp-preserve-order")] + preserve_order, + } + } +} + impl ManifestFormat for PythonFormat { fn manifest_buf(&self, val: Val, buf: &mut String) -> Result<()> { match val { @@ -17,6 +26,8 @@ Val::Null => buf.push_str("None"), Val::Str(s) => escape_string_json_buf(&s.to_string(), buf), Val::Num(_) => ToStringFormat.manifest_buf(val, buf)?, + #[cfg(feature = "exp-bigint")] + Val::BigInt(_) => ToStringFormat.manifest_buf(val, buf)?, Val::Arr(arr) => { buf.push('['); for (i, el) in arr.iter().enumerate() { @@ -57,7 +68,14 @@ preserve_order: bool, } -impl PythonVarsFormat {} +impl PythonVarsFormat { + pub fn std(#[cfg(feature = "exp-preserve-order")] preserve_order: bool) -> Self { + Self { + #[cfg(feature = "exp-preserve-order")] + preserve_order, + } + } +} impl ManifestFormat for PythonVarsFormat { fn manifest_buf(&self, val: Val, buf: &mut String) -> Result<()> { --- 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('='); -- gitstuff