git.delta.rocks / jrsonnet / refs/commits / 85c2a4616ecc

difftreelog

fix Use variable names from jsonnet stdlib for is_x builtins

Jack Stephenson2022-11-30parent: #e70aa7d.patch.diff
in: master
This changes the variable name in the identity-related `is_X` builtin
functions to match the variable names in the [jsonnet standard
library](https://github.com/google/jsonnet/blob/master/stdlib/std.jsonnet#L28,L33).

This mainly serves to integrate better with libraries such as
[k8s-libsonnet](https://github.com/jsonnet-libs/k8s-libsonnet/).

1 file changed

modifiedcrates/jrsonnet-stdlib/src/types.rsdiffbeforeafterboth
before · crates/jrsonnet-stdlib/src/types.rs
1use jrsonnet_evaluator::{error::Result, function::builtin, typed::Any, IStr, Val};23#[builtin]4pub fn builtin_type(x: Any) -> Result<IStr> {5	Ok(x.0.value_type().name().into())6}78#[builtin]9pub fn builtin_is_string(x: Any) -> Result<bool> {10	Ok(matches!(x.0, Val::Str(_)))11}12#[builtin]13pub fn builtin_is_number(x: Any) -> Result<bool> {14	Ok(matches!(x.0, Val::Num(_)))15}16#[builtin]17pub fn builtin_is_boolean(x: Any) -> Result<bool> {18	Ok(matches!(x.0, Val::Bool(_)))19}20#[builtin]21pub fn builtin_is_object(x: Any) -> Result<bool> {22	Ok(matches!(x.0, Val::Obj(_)))23}24#[builtin]25pub fn builtin_is_array(x: Any) -> Result<bool> {26	Ok(matches!(x.0, Val::Arr(_)))27}28#[builtin]29pub fn builtin_is_function(x: Any) -> Result<bool> {30	Ok(matches!(x.0, Val::Func(_)))31}
after · crates/jrsonnet-stdlib/src/types.rs
1use jrsonnet_evaluator::{error::Result, function::builtin, typed::Any, IStr, Val};23#[builtin]4pub fn builtin_type(v: Any) -> Result<IStr> {5	Ok(v.0.value_type().name().into())6}78#[builtin]9pub fn builtin_is_string(v: Any) -> Result<bool> {10	Ok(matches!(v.0, Val::Str(_)))11}12#[builtin]13pub fn builtin_is_number(v: Any) -> Result<bool> {14	Ok(matches!(v.0, Val::Num(_)))15}16#[builtin]17pub fn builtin_is_boolean(v: Any) -> Result<bool> {18	Ok(matches!(v.0, Val::Bool(_)))19}20#[builtin]21pub fn builtin_is_object(v: Any) -> Result<bool> {22	Ok(matches!(v.0, Val::Obj(_)))23}24#[builtin]25pub fn builtin_is_array(v: Any) -> Result<bool> {26	Ok(matches!(v.0, Val::Arr(_)))27}28#[builtin]29pub fn builtin_is_function(v: Any) -> Result<bool> {30	Ok(matches!(v.0, Val::Func(_)))31}