difftreelog
feat add std.objectRemoveKey
in: master
Upstream issue: https://github.com/google/go-jsonnet/pull/686
2 files changed
crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth139 // Objects139 // Objects140 ("objectFieldsEx", builtin_object_fields_ex::INST),140 ("objectFieldsEx", builtin_object_fields_ex::INST),141 ("objectHasEx", builtin_object_has_ex::INST),141 ("objectHasEx", builtin_object_has_ex::INST),142 ("objectRemoveKey", builtin_object_remove_key::INST),142 // Manifest143 // Manifest143 ("escapeStringJson", builtin_escape_string_json::INST),144 ("escapeStringJson", builtin_escape_string_json::INST),144 ("manifestJsonEx", builtin_manifest_json_ex::INST),145 ("manifestJsonEx", builtin_manifest_json_ex::INST),crates/jrsonnet-stdlib/src/objects.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/objects.rs
+++ b/crates/jrsonnet-stdlib/src/objects.rs
@@ -1,9 +1,10 @@
use jrsonnet_evaluator::{
function::builtin,
val::{StrValue, Val},
- IStr, ObjValue,
+ IStr, ObjValue, ObjValueBuilder,
};
+
#[builtin]
pub fn builtin_object_fields_ex(
obj: ObjValue,
@@ -27,3 +28,16 @@
pub fn builtin_object_has_ex(obj: ObjValue, fname: IStr, hidden: bool) -> bool {
obj.has_field_ex(fname, hidden)
}
+
+#[builtin]
+pub fn builtin_object_remove_key(obj: ObjValue, key: IStr) -> ObjValue {
+ let mut new_obj = ObjValueBuilder::with_capacity(obj.len() - 1);
+ for (k, v) in obj.iter() {
+ if k == key {
+ continue
+ }
+ new_obj.member(k).value_unchecked(v.unwrap())
+ }
+
+ new_obj.build()
+}