git.delta.rocks / jrsonnet / refs/commits / 480843191a79

difftreelog

feat DestructRest in object destructuring

prkunoywYaroslav Bolyukin2026-03-23parent: #0afd461.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-evaluator/src/evaluate/destructure.rsdiffbeforeafterboth
107 }107 }
108 #[cfg(feature = "exp-destruct")]108 #[cfg(feature = "exp-destruct")]
109 Destruct::Object { fields, rest } => {109 Destruct::Object { fields, rest } => {
110 use crate::ObjValueBuilder;
111 use jrsonnet_ir::DestructRest;
112 use rustc_hash::FxHashSet;
113
114 let captured_fields: FxHashSet<_> = fields.iter().map(|f| f.0.clone()).collect();
110 let field_names: Vec<_> = fields115 let field_names: Vec<_> = fields
111 .iter()116 .iter()
112 .map(|f| (f.0.clone(), f.2.is_some()))117 .map(|f| (f.0.clone(), f.2.is_some()))
131 Ok(obj)136 Ok(obj)
132 });137 });
138
139 match rest {
140 Some(DestructRest::Keep(v)) => {
141 let full = full.clone();
142 destruct(
143 &Destruct::Full(v.clone()),
144 Thunk!(move || {
145 let full = full.evaluate()?;
146 let mut builder = ObjValueBuilder::new();
147 builder
148 .reserve_cores(1)
149 .extend_with_core(full.as_standalone());
150 builder.with_fields_omitted(captured_fields);
151 Ok(Val::Obj(builder.build()))
152 }),
153 fctx.clone(),
154 new_bindings,
155 )?;
156 }
157 Some(DestructRest::Drop) | None => {}
158 }
133159
134 for (field, d, default) in fields {160 for (field, d, default) in fields {
135 let default = default.clone().map(|e| (fctx.clone(), e));161 let default = default.clone().map(|e| (fctx.clone(), e));
modifiedcrates/jrsonnet-evaluator/src/obj/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj/mod.rs
+++ b/crates/jrsonnet-evaluator/src/obj/mod.rs
@@ -158,6 +158,7 @@
 pub type EnumFieldsHandler<'a> =
 	dyn FnMut(SuperDepth, FieldIndex, IStr, EnumFields) -> ControlFlow<()> + 'a;
 
+#[derive(Debug)]
 pub enum EnumFields {
 	Normal(Visibility),
 	Omit(Skip),
@@ -289,7 +290,7 @@
 }
 
 #[derive(Trace, Debug)]
-struct StandaloneSuperCore {
+pub(crate) struct StandaloneSuperCore {
 	sup: CoreIdx,
 	this: ObjValue,
 }
@@ -791,6 +792,14 @@
 			key,
 		})
 	}
+	pub(crate) fn as_standalone(&self) -> StandaloneSuperCore {
+		StandaloneSuperCore {
+			sup: CoreIdx {
+				idx: self.0.cores.len(),
+			},
+			this: self.clone(),
+		}
+	}
 	pub fn ptr_eq(a: &Self, b: &Self) -> bool {
 		Cc::ptr_eq(&a.0, &b.0)
 	}