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
1use jrsonnet_evaluator::{error::Result, function::builtin, typed::Any, IStr, Val};1use jrsonnet_evaluator::{error::Result, function::builtin, typed::Any, IStr, Val};
22
3#[builtin]3#[builtin]
4pub fn builtin_type(x: Any) -> Result<IStr> {4pub fn builtin_type(v: Any) -> Result<IStr> {
5 Ok(x.0.value_type().name().into())5 Ok(v.0.value_type().name().into())
6}6}
77
8#[builtin]8#[builtin]
9pub fn builtin_is_string(x: Any) -> Result<bool> {9pub fn builtin_is_string(v: Any) -> Result<bool> {
10 Ok(matches!(x.0, Val::Str(_)))10 Ok(matches!(v.0, Val::Str(_)))
11}11}
12#[builtin]12#[builtin]
13pub fn builtin_is_number(x: Any) -> Result<bool> {13pub fn builtin_is_number(v: Any) -> Result<bool> {
14 Ok(matches!(x.0, Val::Num(_)))14 Ok(matches!(v.0, Val::Num(_)))
15}15}
16#[builtin]16#[builtin]
17pub fn builtin_is_boolean(x: Any) -> Result<bool> {17pub fn builtin_is_boolean(v: Any) -> Result<bool> {
18 Ok(matches!(x.0, Val::Bool(_)))18 Ok(matches!(v.0, Val::Bool(_)))
19}19}
20#[builtin]20#[builtin]
21pub fn builtin_is_object(x: Any) -> Result<bool> {21pub fn builtin_is_object(v: Any) -> Result<bool> {
22 Ok(matches!(x.0, Val::Obj(_)))22 Ok(matches!(v.0, Val::Obj(_)))
23}23}
24#[builtin]24#[builtin]
25pub fn builtin_is_array(x: Any) -> Result<bool> {25pub fn builtin_is_array(v: Any) -> Result<bool> {
26 Ok(matches!(x.0, Val::Arr(_)))26 Ok(matches!(v.0, Val::Arr(_)))
27}27}
28#[builtin]28#[builtin]
29pub fn builtin_is_function(x: Any) -> Result<bool> {29pub fn builtin_is_function(v: Any) -> Result<bool> {
30 Ok(matches!(x.0, Val::Func(_)))30 Ok(matches!(v.0, Val::Func(_)))
31}31}
3232