git.delta.rocks / jrsonnet / refs/commits / 3fc6c25f159a

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2021-01-24parent: #2634495.patch.diff
in: master

9 files changed

modifiedcrates/jrsonnet-evaluator/src/builtin/manifest.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/manifest.rs
@@ -42,7 +42,7 @@
 			}
 		}
 		Val::Null => buf.push_str("null"),
-		Val::Str(s) => buf.push_str(&escape_string_json(&s)),
+		Val::Str(s) => buf.push_str(&escape_string_json(s)),
 		Val::Num(n) => write!(buf, "{}", n).unwrap(),
 		Val::Arr(items) => {
 			buf.push('[');
modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -445,7 +445,7 @@
 			},
 			Val::Arr(a) => {
 				base64::encode(a.iter().map(|v| {
-					Ok(v?.clone().unwrap_num()? as u8)
+					Ok(v?.unwrap_num()? as u8)
 				}).collect::<Result<Vec<_>>>()?).into()
 			},
 			_ => unreachable!()
@@ -589,7 +589,7 @@
 	name: &str,
 	args: &ArgsDesc,
 ) -> Result<Val> {
-	if let Some(f) = BUILTINS.with(|builtins| builtins.get(name).map(|f| *f)) {
+	if let Some(f) = BUILTINS.with(|builtins| builtins.get(name).copied()) {
 		return Ok(f(context, loc, args)?);
 	}
 	throw!(IntrinsicNotFound(name.into()))
modifiedcrates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate.rs
@@ -473,7 +473,6 @@
 					}
 					v.get(n as usize)?
 						.ok_or_else(|| ArrayBoundsError(n as usize, v.len()))?
-						.clone()
 				}
 				(Val::Arr(_), Val::Str(n)) => throw!(AttemptedIndexAnArrayWithString(n)),
 				(Val::Arr(_), n) => throw!(ValueIndexMustBeTypeGot(
modifiedcrates/jrsonnet-evaluator/src/native.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/native.rs
+++ b/crates/jrsonnet-evaluator/src/native.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::type_complexity)]
+
 use crate::{error::Result, Val};
 use jrsonnet_parser::ParamsDesc;
 use std::fmt::Debug;
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -34,7 +34,7 @@
 		}
 		let mut debug = f.debug_struct("ObjValue");
 		for (name, member) in self.0.this_entries.iter() {
-			debug.field(&name, member);
+			debug.field(name, member);
 		}
 		#[cfg(feature = "unstable")]
 		{
@@ -140,7 +140,7 @@
 			.evaluate()?)
 	}
 
-	pub fn ptr_eq(a: &ObjValue, b: &ObjValue) -> bool {
+	pub fn ptr_eq(a: &Self, b: &Self) -> bool {
 		Rc::ptr_eq(&a.0, &b.0)
 	}
 }
modifiedcrates/jrsonnet-evaluator/src/typed.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/typed.rs
+++ b/crates/jrsonnet-evaluator/src/typed.rs
@@ -29,7 +29,7 @@
 pub struct TypeLocError(Box<TypeError>, ValuePathStack);
 impl From<TypeError> for TypeLocError {
 	fn from(e: TypeError) -> Self {
-		TypeLocError(Box::new(e), ValuePathStack(Vec::new()))
+		Self(Box::new(e), ValuePathStack(Vec::new()))
 	}
 }
 impl From<TypeLocError> for LocError {
@@ -61,7 +61,7 @@
 			write!(out, "{}", err)?;
 
 			for (i, line) in out.lines().enumerate() {
-				if line.trim().len() == 0 {
+				if line.trim().is_empty() {
 					continue;
 				}
 				if i != 0 {
@@ -118,8 +118,8 @@
 impl Display for ValuePathItem {
 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 		match self {
-			ValuePathItem::Field(name) => write!(f, ".{}", name)?,
-			ValuePathItem::Index(idx) => write!(f, "[{}]", idx)?,
+			Self::Field(name) => write!(f, ".{}", name)?,
+			Self::Index(idx) => write!(f, "[{}]", idx)?,
 		}
 		Ok(())
 	}
@@ -140,25 +140,25 @@
 impl CheckType for ComplexValType {
 	fn check(&self, value: &Val) -> Result<()> {
 		match self {
-			ComplexValType::Any => Ok(()),
-			ComplexValType::Simple(s) => s.check(value),
-			ComplexValType::Char => match value {
+			Self::Any => Ok(()),
+			Self::Simple(s) => s.check(value),
+			Self::Char => match value {
 				Val::Str(s) if s.len() == 1 || s.chars().count() == 1 => Ok(()),
 				v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
 			},
-			ComplexValType::BoundedNumber(from, to) => {
+			Self::BoundedNumber(from, to) => {
 				if let Val::Num(n) = value {
 					if from.map(|from| from > *n).unwrap_or(false)
 						|| to.map(|to| to <= *n).unwrap_or(false)
 					{
-						return Err(TypeError::BoundsFailed(*n, from.clone(), to.clone()).into());
+						return Err(TypeError::BoundsFailed(*n, *from, *to).into());
 					}
 					Ok(())
 				} else {
 					Err(TypeError::ExpectedGot(self.clone(), value.value_type()).into())
 				}
 			}
-			ComplexValType::Array(elem_type) => match value {
+			Self::Array(elem_type) => match value {
 				Val::Arr(a) => {
 					for (i, item) in a.iter().enumerate() {
 						push_type(
@@ -170,9 +170,9 @@
 					}
 					Ok(())
 				}
-				v => return Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
+				v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
 			},
-			ComplexValType::ArrayRef(elem_type) => match value {
+			Self::ArrayRef(elem_type) => match value {
 				Val::Arr(a) => {
 					for (i, item) in a.iter().enumerate() {
 						push_type(
@@ -184,9 +184,9 @@
 					}
 					Ok(())
 				}
-				v => return Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
+				v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
 			},
-			ComplexValType::ObjectRef(elems) => match value {
+			Self::ObjectRef(elems) => match value {
 				Val::Obj(obj) => {
 					for (k, v) in elems.iter() {
 						if let Some(got_v) = obj.get((*k).into())? {
@@ -202,11 +202,11 @@
 							);
 						}
 					}
-					return Ok(());
+					Ok(())
 				}
-				v => return Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
+				v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),
 			},
-			ComplexValType::Union(types) => {
+			Self::Union(types) => {
 				let mut errors = Vec::new();
 				for ty in types.iter() {
 					match ty.check(value) {
@@ -219,9 +219,9 @@
 						},
 					}
 				}
-				return Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into());
+				Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into())
 			}
-			ComplexValType::UnionRef(types) => {
+			Self::UnionRef(types) => {
 				let mut errors = Vec::new();
 				for ty in types.iter() {
 					match ty.check(value) {
@@ -234,15 +234,15 @@
 						},
 					}
 				}
-				return Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into());
+				Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into())
 			}
-			ComplexValType::Sum(types) => {
+			Self::Sum(types) => {
 				for ty in types.iter() {
 					ty.check(value)?
 				}
 				Ok(())
 			}
-			ComplexValType::SumRef(types) => {
+			Self::SumRef(types) => {
 				for ty in types.iter() {
 					ty.check(value)?
 				}
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/val.rs
1use crate::{2	builtin::{3		call_builtin,4		manifest::{manifest_json_ex, ManifestJsonOptions, ManifestType},5	},6	error::Error::*,7	evaluate,8	function::{parse_function_call, parse_function_call_map, place_args},9	native::NativeCallback,10	throw, with_state, Context, ObjValue, Result,11};12use jrsonnet_interner::IStr;13use jrsonnet_parser::{el, Arg, ArgsDesc, Expr, ExprLocation, LiteralType, LocExpr, ParamsDesc};14use jrsonnet_types::ValType;15use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};1617enum LazyValInternals {18	Computed(Val),19	Waiting(Box<dyn Fn() -> Result<Val>>),20}21#[derive(Clone)]22pub struct LazyVal(Rc<RefCell<LazyValInternals>>);23impl LazyVal {24	pub fn new(f: Box<dyn Fn() -> Result<Val>>) -> Self {25		Self(Rc::new(RefCell::new(LazyValInternals::Waiting(f))))26	}27	pub fn new_resolved(val: Val) -> Self {28		Self(Rc::new(RefCell::new(LazyValInternals::Computed(val))))29	}30	pub fn evaluate(&self) -> Result<Val> {31		let new_value = match &*self.0.borrow() {32			LazyValInternals::Computed(v) => return Ok(v.clone()),33			LazyValInternals::Waiting(f) => f()?,34		};35		*self.0.borrow_mut() = LazyValInternals::Computed(new_value.clone());36		Ok(new_value)37	}38}3940#[macro_export]41macro_rules! lazy_val {42	($f: expr) => {43		$crate::LazyVal::new(Box::new($f))44	};45}46#[macro_export]47macro_rules! resolved_lazy_val {48	($f: expr) => {49		$crate::LazyVal::new_resolved($f)50	};51}52impl Debug for LazyVal {53	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {54		write!(f, "Lazy")55	}56}57impl PartialEq for LazyVal {58	fn eq(&self, other: &Self) -> bool {59		Rc::ptr_eq(&self.0, &other.0)60	}61}6263#[derive(Debug, PartialEq)]64pub struct FuncDesc {65	pub name: IStr,66	pub ctx: Context,67	pub params: ParamsDesc,68	pub body: LocExpr,69}7071#[derive(Debug)]72pub enum FuncVal {73	/// Plain function implemented in jsonnet74	Normal(FuncDesc),75	/// Standard library function76	Intrinsic(IStr),77	/// Library functions implemented in native78	NativeExt(IStr, Rc<NativeCallback>),79}8081impl PartialEq for FuncVal {82	fn eq(&self, other: &Self) -> bool {83		match (self, other) {84			(Self::Normal(a), Self::Normal(b)) => a == b,85			(Self::Intrinsic(an), Self::Intrinsic(bn)) => an == bn,86			(Self::NativeExt(an, _), Self::NativeExt(bn, _)) => an == bn,87			(..) => false,88		}89	}90}91impl FuncVal {92	pub fn is_ident(&self) -> bool {93		matches!(&self, Self::Intrinsic(n) if n as &str == "id")94	}95	pub fn name(&self) -> IStr {96		match self {97			Self::Normal(normal) => normal.name.clone(),98			Self::Intrinsic(name) => format!("std.{}", name).into(),99			Self::NativeExt(n, _) => format!("native.{}", n).into(),100		}101	}102	pub fn evaluate(103		&self,104		call_ctx: Context,105		loc: Option<&ExprLocation>,106		args: &ArgsDesc,107		tailstrict: bool,108	) -> Result<Val> {109		match self {110			Self::Normal(func) => {111				let ctx = parse_function_call(112					call_ctx,113					Some(func.ctx.clone()),114					&func.params,115					args,116					tailstrict,117				)?;118				evaluate(ctx, &func.body)119			}120			Self::Intrinsic(name) => call_builtin(call_ctx, loc, name, args),121			Self::NativeExt(_name, handler) => {122				let args = parse_function_call(call_ctx, None, &handler.params, args, true)?;123				let mut out_args = Vec::with_capacity(handler.params.len());124				for p in handler.params.0.iter() {125					out_args.push(args.binding(p.0.clone())?.evaluate()?);126				}127				Ok(handler.call(loc.clone().map(|l| l.0.clone()), &out_args)?)128			}129		}130	}131132	pub fn evaluate_map(133		&self,134		call_ctx: Context,135		args: &HashMap<IStr, Val>,136		tailstrict: bool,137	) -> Result<Val> {138		match self {139			Self::Normal(func) => {140				let ctx = parse_function_call_map(141					call_ctx,142					Some(func.ctx.clone()),143					&func.params,144					args,145					tailstrict,146				)?;147				evaluate(ctx, &func.body)148			}149			Self::Intrinsic(_) => todo!(),150			Self::NativeExt(_, _) => todo!(),151		}152	}153154	pub fn evaluate_values(&self, call_ctx: Context, args: &[Val]) -> Result<Val> {155		match self {156			Self::Normal(func) => {157				let ctx = place_args(call_ctx, Some(func.ctx.clone()), &func.params, args)?;158				evaluate(ctx, &func.body)159			}160			Self::Intrinsic(_) => todo!(),161			Self::NativeExt(_, _) => todo!(),162		}163	}164}165166#[derive(Clone)]167pub enum ManifestFormat {168	YamlStream(Box<ManifestFormat>),169	Yaml(usize),170	Json(usize),171	ToString,172	String,173}174175#[derive(Debug, Clone)]176pub enum ArrValue {177	Lazy(Rc<Vec<LazyVal>>),178	Eager(Rc<Vec<Val>>),179	Extended(Box<(ArrValue, ArrValue)>),180}181impl ArrValue {182	pub fn len(&self) -> usize {183		match self {184			ArrValue::Lazy(l) => l.len(),185			ArrValue::Eager(e) => e.len(),186			ArrValue::Extended(v) => v.0.len() + v.1.len(),187		}188	}189190	pub fn is_empty(&self) -> bool {191		self.len() == 0192	}193194	pub fn get(&self, index: usize) -> Result<Option<Val>> {195		match self {196			ArrValue::Lazy(vec) => {197				if let Some(v) = vec.get(index) {198					Ok(Some(v.evaluate()?))199				} else {200					Ok(None)201				}202			}203			ArrValue::Eager(vec) => Ok(vec.get(index).cloned()),204			ArrValue::Extended(v) => {205				let a_len = v.0.len();206				if a_len > index {207					v.0.get(index)208				} else {209					v.1.get(index - a_len)210				}211			}212		}213	}214215	pub fn get_lazy(&self, index: usize) -> Option<LazyVal> {216		match self {217			ArrValue::Lazy(vec) => vec.get(index).cloned(),218			ArrValue::Eager(vec) => vec219				.get(index)220				.cloned()221				.map(|val| LazyVal::new_resolved(val)),222			ArrValue::Extended(v) => {223				let a_len = v.0.len();224				if a_len > index {225					v.0.get_lazy(index)226				} else {227					v.1.get_lazy(index - a_len)228				}229			}230		}231	}232233	pub fn evaluated(&self) -> Result<Rc<Vec<Val>>> {234		Ok(match self {235			ArrValue::Lazy(vec) => {236				let mut out = Vec::with_capacity(vec.len());237				for item in vec.iter() {238					out.push(item.evaluate()?);239				}240				Rc::new(out)241			}242			ArrValue::Eager(vec) => vec.clone(),243			ArrValue::Extended(v) => {244				let mut out = Vec::with_capacity(self.len());245				for item in self.iter() {246					out.push(item?);247				}248				Rc::new(out)249			}250		})251	}252253	pub fn iter(&self) -> impl DoubleEndedIterator<Item = Result<Val>> + '_ {254		(0..self.len()).map(move |idx| match self {255			ArrValue::Lazy(l) => l[idx].evaluate(),256			ArrValue::Eager(e) => Ok(e[idx].clone()),257			ArrValue::Extended(_) => self.get(idx).map(|e| e.unwrap()),258		})259	}260261	pub fn iter_lazy(&self) -> impl DoubleEndedIterator<Item = LazyVal> + '_ {262		(0..self.len()).map(move |idx| match self {263			ArrValue::Lazy(l) => l[idx].clone(),264			ArrValue::Eager(e) => LazyVal::new_resolved(e[idx].clone()),265			ArrValue::Extended(_) => self.get_lazy(idx).unwrap(),266		})267	}268269	pub fn reversed(self) -> Self {270		match self {271			ArrValue::Lazy(vec) => {272				let mut out = (&vec as &Vec<_>).clone();273				out.reverse();274				Self::Lazy(Rc::new(out))275			}276			ArrValue::Eager(vec) => {277				let mut out = (&vec as &Vec<_>).clone();278				out.reverse();279				Self::Eager(Rc::new(out))280			}281			ArrValue::Extended(b) => ArrValue::Extended(Box::new((b.1.reversed(), b.0.reversed()))),282		}283	}284285	pub fn ptr_eq(a: &ArrValue, b: &ArrValue) -> bool {286		match (a, b) {287			(ArrValue::Lazy(a), ArrValue::Lazy(b)) => Rc::ptr_eq(a, b),288			(ArrValue::Eager(a), ArrValue::Eager(b)) => Rc::ptr_eq(a, b),289			_ => false,290		}291	}292}293294impl From<Vec<LazyVal>> for ArrValue {295	fn from(v: Vec<LazyVal>) -> Self {296		Self::Lazy(Rc::new(v))297	}298}299300impl From<Vec<Val>> for ArrValue {301	fn from(v: Vec<Val>) -> Self {302		Self::Eager(Rc::new(v))303	}304}305306#[derive(Debug, Clone)]307pub enum Val {308	Bool(bool),309	Null,310	Str(IStr),311	Num(f64),312	Arr(ArrValue),313	Obj(ObjValue),314	Func(Rc<FuncVal>),315}316317macro_rules! matches_unwrap {318	($e: expr, $p: pat, $r: expr) => {319		match $e {320			$p => $r,321			_ => panic!("no match"),322			}323	};324}325impl Val {326	/// Creates `Val::Num` after checking for numeric overflow.327	/// As numbers are `f64`, we can just check for their finity.328	pub fn new_checked_num(num: f64) -> Result<Self> {329		if num.is_finite() {330			Ok(Self::Num(num))331		} else {332			throw!(RuntimeError("overflow".into()))333		}334	}335336	pub fn assert_type(&self, context: &'static str, val_type: ValType) -> Result<()> {337		let this_type = self.value_type();338		if this_type != val_type {339			throw!(TypeMismatch(context, vec![val_type], this_type))340		} else {341			Ok(())342		}343	}344	pub fn unwrap_num(self) -> Result<f64> {345		Ok(matches_unwrap!(self, Self::Num(v), v))346	}347	pub fn unwrap_func(self) -> Result<Rc<FuncVal>> {348		Ok(matches_unwrap!(self, Self::Func(v), v))349	}350	pub fn try_cast_bool(self, context: &'static str) -> Result<bool> {351		self.assert_type(context, ValType::Bool)?;352		Ok(matches_unwrap!(self, Self::Bool(v), v))353	}354	pub fn try_cast_str(self, context: &'static str) -> Result<IStr> {355		self.assert_type(context, ValType::Str)?;356		Ok(matches_unwrap!(self, Self::Str(v), v))357	}358	pub fn try_cast_num(self, context: &'static str) -> Result<f64> {359		self.assert_type(context, ValType::Num)?;360		self.unwrap_num()361	}362	pub fn value_type(&self) -> ValType {363		match self {364			Self::Str(..) => ValType::Str,365			Self::Num(..) => ValType::Num,366			Self::Arr(..) => ValType::Arr,367			Self::Obj(..) => ValType::Obj,368			Self::Bool(_) => ValType::Bool,369			Self::Null => ValType::Null,370			Self::Func(..) => ValType::Func,371		}372	}373374	pub fn to_string(&self) -> Result<IStr> {375		Ok(match self {376			Self::Bool(true) => "true".into(),377			Self::Bool(false) => "false".into(),378			Self::Null => "null".into(),379			Self::Str(s) => s.clone(),380			v => manifest_json_ex(381				&v,382				&ManifestJsonOptions {383					padding: "",384					mtype: ManifestType::ToString,385				},386			)?387			.into(),388		})389	}390391	/// Expects value to be object, outputs (key, manifested value) pairs392	pub fn manifest_multi(&self, ty: &ManifestFormat) -> Result<Vec<(IStr, IStr)>> {393		let obj = match self {394			Self::Obj(obj) => obj,395			_ => throw!(MultiManifestOutputIsNotAObject),396		};397		let keys = obj.visible_fields();398		let mut out = Vec::with_capacity(keys.len());399		for key in keys {400			let value = obj401				.get(key.clone())?402				.expect("item in object")403				.manifest(ty)?;404			out.push((key, value));405		}406		Ok(out)407	}408409	/// Expects value to be array, outputs manifested values410	pub fn manifest_stream(&self, ty: &ManifestFormat) -> Result<Vec<IStr>> {411		let arr = match self {412			Self::Arr(a) => a,413			_ => throw!(StreamManifestOutputIsNotAArray),414		};415		let mut out = Vec::with_capacity(arr.len());416		for i in arr.iter() {417			out.push(i?.manifest(ty)?);418		}419		Ok(out)420	}421422	pub fn manifest(&self, ty: &ManifestFormat) -> Result<IStr> {423		Ok(match ty {424			ManifestFormat::YamlStream(format) => {425				let arr = match self {426					Self::Arr(a) => a,427					_ => throw!(StreamManifestOutputIsNotAArray),428				};429				let mut out = String::new();430431				match format as &ManifestFormat {432					ManifestFormat::YamlStream(_) => throw!(StreamManifestOutputCannotBeRecursed),433					ManifestFormat::String => throw!(StreamManifestCannotNestString),434					_ => {}435				};436437				if !arr.is_empty() {438					for v in arr.iter() {439						out.push_str("---\n");440						out.push_str(&v?.manifest(format)?);441						out.push('\n');442					}443					out.push_str("...");444				}445446				out.into()447			}448			ManifestFormat::Yaml(padding) => self.to_yaml(*padding)?,449			ManifestFormat::Json(padding) => self.to_json(*padding)?,450			ManifestFormat::ToString => self.to_string()?,451			ManifestFormat::String => match self {452				Self::Str(s) => s.clone(),453				_ => throw!(StringManifestOutputIsNotAString),454			},455		})456	}457458	/// For manifestification459	pub fn to_json(&self, padding: usize) -> Result<IStr> {460		manifest_json_ex(461			self,462			&ManifestJsonOptions {463				padding: &" ".repeat(padding),464				mtype: if padding == 0 {465					ManifestType::Minify466				} else {467					ManifestType::Manifest468				},469			},470		)471		.map(|s| s.into())472	}473474	/// Calls `std.manifestJson`475	#[cfg(feature = "faster")]476	pub fn to_std_json(&self, padding: usize) -> Result<Rc<str>> {477		manifest_json_ex(478			self,479			&ManifestJsonOptions {480				padding: &" ".repeat(padding),481				mtype: ManifestType::Std,482			},483		)484		.map(|s| s.into())485	}486487	/// Calls `std.manifestJson`488	#[cfg(not(feature = "faster"))]489	pub fn to_std_json(&self, padding: usize) -> Result<Rc<str>> {490		with_state(|s| {491			let ctx = s492				.create_default_context()?493				.with_var("__tmp__to_json__".into(), self.clone())?;494			Ok(evaluate(495				ctx,496				&el!(Expr::Apply(497					el!(Expr::Index(498						el!(Expr::Var("std".into())),499						el!(Expr::Str("manifestJsonEx".into()))500					)),501					ArgsDesc(vec![502						Arg(None, el!(Expr::Var("__tmp__to_json__".into()))),503						Arg(None, el!(Expr::Str(" ".repeat(padding).into())))504					]),505					false506				)),507			)?508			.try_cast_str("to json")?)509		})510	}511	pub fn to_yaml(&self, padding: usize) -> Result<IStr> {512		with_state(|s| {513			let ctx = s514				.create_default_context()?515				.with_var("__tmp__to_json__".into(), self.clone());516			Ok(evaluate(517				ctx,518				&el!(Expr::Apply(519					el!(Expr::Index(520						el!(Expr::Var("std".into())),521						el!(Expr::Str("manifestYamlDoc".into()))522					)),523					ArgsDesc(vec![524						Arg(None, el!(Expr::Var("__tmp__to_json__".into()))),525						Arg(526							None,527							el!(Expr::Literal(if padding != 0 {528								LiteralType::True529							} else {530								LiteralType::False531							}))532						)533					]),534					false535				)),536			)?537			.try_cast_str("to json")?)538		})539	}540}541542const fn is_function_like(val: &Val) -> bool {543	matches!(val, Val::Func(_))544}545546/// Native implementation of `std.primitiveEquals`547pub fn primitive_equals(val_a: &Val, val_b: &Val) -> Result<bool> {548	Ok(match (val_a, val_b) {549		(Val::Bool(a), Val::Bool(b)) => a == b,550		(Val::Null, Val::Null) => true,551		(Val::Str(a), Val::Str(b)) => a == b,552		(Val::Num(a), Val::Num(b)) => (a - b).abs() <= f64::EPSILON,553		(Val::Arr(_), Val::Arr(_)) => throw!(RuntimeError(554			"primitiveEquals operates on primitive types, got array".into(),555		)),556		(Val::Obj(_), Val::Obj(_)) => throw!(RuntimeError(557			"primitiveEquals operates on primitive types, got object".into(),558		)),559		(a, b) if is_function_like(&a) && is_function_like(&b) => {560			throw!(RuntimeError("cannot test equality of functions".into()))561		}562		(_, _) => false,563	})564}565566/// Native implementation of `std.equals`567pub fn equals(val_a: &Val, val_b: &Val) -> Result<bool> {568	if val_a.value_type() != val_b.value_type() {569		return Ok(false);570	}571	match (val_a, val_b) {572		(Val::Arr(a), Val::Arr(b)) => {573			if ArrValue::ptr_eq(a, b) {574				return Ok(true);575			}576			if a.len() != b.len() {577				return Ok(false);578			}579			for (a, b) in a.iter().zip(b.iter()) {580				if !equals(&a?, &b?)? {581					return Ok(false);582				}583			}584			Ok(true)585		}586		(Val::Obj(a), Val::Obj(b)) => {587			if ObjValue::ptr_eq(a, b) {588				return Ok(true);589			}590			let fields = a.visible_fields();591			if fields != b.visible_fields() {592				return Ok(false);593			}594			for field in fields {595				if !equals(&a.get(field.clone())?.unwrap(), &b.get(field)?.unwrap())? {596					return Ok(false);597				}598			}599			Ok(true)600		}601		(a, b) => Ok(primitive_equals(&a, &b)?),602	}603}
modifiedcrates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-interner/src/lib.rs
+++ b/crates/jrsonnet-interner/src/lib.rs
@@ -68,7 +68,7 @@
 		IStr(STR_POOL.with(|pool| {
 			let mut pool = pool.borrow_mut();
 			if let Some((k, _)) = pool.get_key_value(str) {
-				return k.clone();
+				k.clone()
 			} else {
 				let rc: Rc<str> = str.into();
 				pool.insert(rc.clone(), ());
modifiedcrates/jrsonnet-types/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-types/src/lib.rs
+++ b/crates/jrsonnet-types/src/lib.rs
@@ -133,10 +133,8 @@
 	union: &[ComplexValType],
 ) -> std::fmt::Result {
 	for (i, v) in union.iter().enumerate() {
-		let should_add_braces = match v {
-			ComplexValType::UnionRef(_) | ComplexValType::Union(_) if !is_union => true,
-			_ => false,
-		};
+		let should_add_braces =
+			matches!(v, ComplexValType::UnionRef(_) | ComplexValType::Union(_) if !is_union);
 		if i != 0 {
 			write!(f, " {} ", if is_union { '|' } else { '&' })?;
 		}