git.delta.rocks / jrsonnet / refs/commits / 6d7ca685fe74

difftreelog

source

crates/jrsonnet-stdlib/src/operator.rs948 Bsourcehistory
1//! Some jsonnet operations are desugared to stdlib functions...2//! However, in our case we instead implement them in native, and implement native functions on top of core for backwards compatibility34use jrsonnet_evaluator::{5	error::Result,6	function::builtin,7	operator::evaluate_mod_op,8	stdlib::std_format,9	typed::{Any, Either, Either2},10	val::{equals, primitive_equals},11	IStr, State, Val,12};1314#[builtin]15pub fn builtin_mod(s: State, a: Either![f64, IStr], b: Any) -> Result<Any> {16	use Either2::*;17	Ok(Any(evaluate_mod_op(18		s,19		&match a {20			A(v) => Val::Num(v),21			B(s) => Val::Str(s),22		},23		&b.0,24	)?))25}2627#[builtin]28pub fn builtin_primitive_equals(a: Any, b: Any) -> Result<bool> {29	primitive_equals(&a.0, &b.0)30}3132#[builtin]33pub fn builtin_equals(s: State, a: Any, b: Any) -> Result<bool> {34	equals(s, &a.0, &b.0)35}3637#[builtin]38pub fn builtin_format(s: State, str: IStr, vals: Any) -> Result<String> {39	std_format(s, str, vals.0)40}