git.delta.rocks / jrsonnet / refs/commits / 8ec1af04129d

difftreelog

feat feature-gate regex

Yaroslav Bolyukin2023-12-10parent: #103c2a5.patch.diff
in: master

3 files changed

modifiedcmds/jrsonnet/Cargo.tomldiffbeforeafterboth
before · cmds/jrsonnet/Cargo.toml
1[package]2name = "jrsonnet"3description = "Rust jsonnet implementation"4version.workspace = true5repository.workspace = true6authors = ["Yaroslav Bolyukin <iam@lach.pw>"]7license = "MIT"8edition = "2021"910[features]11experimental = [12    "exp-preserve-order",13    "exp-destruct",14    "exp-null-coaelse",15    "exp-object-iteration",16    "exp-bigint",17    "exp-apply",18]19# Use mimalloc as allocator20mimalloc = ["mimallocator"]21# Experimental feature, which allows to preserve order of object fields22exp-preserve-order = [23    "jrsonnet-evaluator/exp-preserve-order",24    "jrsonnet-cli/exp-preserve-order",25]26# Destructuring of locals27exp-destruct = ["jrsonnet-evaluator/exp-destruct"]28# Iteration over objects yields [key, value] elements29exp-object-iteration = ["jrsonnet-evaluator/exp-object-iteration"]30# Bigint type31exp-bigint = ["jrsonnet-evaluator/exp-bigint", "jrsonnet-cli/exp-bigint"]32# std.regex and co.33exp-regex = [34    "jrsonnet-stdlib/exp-regex",35]36# obj?.field, obj?.['field']37exp-null-coaelse = [38    "jrsonnet-evaluator/exp-null-coaelse",39    "jrsonnet-parser/exp-null-coaelse",40    "jrsonnet-cli/exp-null-coaelse",41]42# --exp-apply43exp-apply = []4445# std.thisFile support46legacy-this-file = ["jrsonnet-cli/legacy-this-file"]4748nightly = ["jrsonnet-evaluator/nightly"]4950[dependencies]51jrsonnet-evaluator.workspace = true52jrsonnet-parser.workspace = true53jrsonnet-cli.workspace = true54jrsonnet-gcmodule.workspace = true5556mimallocator = { workspace = true, optional = true }57thiserror.workspace = true58clap = { workspace = true, features = ["derive"] }59clap_complete.workspace = true60serde_json.workspace = true61serde = { workspace = true, features = ["derive"] }62ass-stroke.workspace = true
modifiedcrates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/typed/conversions.rs
+++ b/crates/jrsonnet-evaluator/src/typed/conversions.rs
@@ -10,7 +10,7 @@
 	bail,
 	function::{native::NativeDesc, FuncDesc, FuncVal},
 	typed::CheckType,
-	val::{IndexableVal, ThunkMapper},
+	val::{IndexableVal, StrValue, ThunkMapper},
 	ObjValue, ObjValueBuilder, Result, Thunk, Val,
 };
 
modifiedcrates/jrsonnet-stdlib/src/regex.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/regex.rs
+++ b/crates/jrsonnet-stdlib/src/regex.rs
@@ -45,7 +45,7 @@
 	let mut named_captures = ObjValueBuilder::with_capacity(regex.capture_names().len());
 
 	let Some(captured) = regex.captures(&str) else {
-		return Ok(Val::Null)
+		return Ok(Val::Null);
 	};
 
 	for ele in captured.iter().skip(1) {
@@ -62,15 +62,14 @@
 		.flat_map(|(i, v)| Some((i, v?)))
 	{
 		let capture = captures[i].clone();
-		named_captures.member(name.into()).value(capture)?;
+		named_captures.field(name).try_value(capture)?;
 	}
 
-	out.member("string".into())
-		.value_unchecked(Val::Str(captured.get(0).unwrap().as_str().into()));
-	out.member("captures".into())
-		.value_unchecked(Val::Arr(captures.into()));
-	out.member("namedCaptures".into())
-		.value_unchecked(Val::Obj(named_captures.build()));
+	out.field("string")
+		.value(Val::Str(captured.get(0).unwrap().as_str().into()));
+	out.field("captures").value(Val::Arr(captures.into()));
+	out.field("namedCaptures")
+		.value(Val::Obj(named_captures.build()));
 
 	Ok(Val::Obj(out.build()))
 }