git.delta.rocks / jrsonnet / refs/commits / 15d127ad474e

difftreelog

doc: extra features

Yaroslav Bolyukin2022-11-20parent: #be6d2bd.patch.diff
in: master

2 files changed

modifiedREADME.mddiffbeforeafterboth
before · README.md
1# jrsonnet23[![release](https://img.shields.io/github/v/tag/CertainLach/jrsonnet?color=%23fb4934&label=latest%20release&style=for-the-badge)](https://github.com/CertainLach/jrsonnet/releases)4[![license](https://img.shields.io/github/license/CertainLach/jrsonnet?color=%2383a598&label=license&style=for-the-badge)](/LICENSE)5[![opencollective](https://img.shields.io/opencollective/all/jrsonnet?color=%238ec07c&style=for-the-badge)](https://opencollective.com/jrsonnet)67## What is it89[Jsonnet](https://jsonnet.org/) is a data templating language1011This Rust crate implements both jsonnet library and an alternative `jsonnet` executable based on it. For more information see [bindings](#Bindings).1213## Install1415### NixOS1617jrsonnet is packaged in nixpkgs and maintained by @CertainLach1819```sh20nix-env -iA nixpkgs.jrsonnet21```2223### MacOS2425jrsonnet is packaged to brew and maintained by @messense2627```sh28brew install jrsonnet29```3031### Windows/other linux distributions3233You can get latest build of jrsonnet in [releases](https://github.com/CertainLach/jrsonnet/releases)3435### Build from sources3637jrsonnet should build on latest stable Rust version (probally on olders, but there is no MSRV policy provided)3839Debug build will work too, but it is much slower than release4041```42cargo build --release43```4445## Why?4647There already are multiple implementations of this standard implemented in different languages: [C++](https://github.com/google/jsonnet), [Go](https://github.com/google/go-jsonnet/), [Scala](https://github.com/databricks/sjsonnet).4849This implementation shows performance better than all existing implementations. For more information see [benchmarks](#Benchmarks).5051In the end, it's always fun to implement something in Rust.5253## Bindings5455### Rust5657[![crates.io](https://img.shields.io/crates/v/jrsonnet-evaluator)](https://crates.io/crates/jrsonnet-evaluator)58[![docs.rs](https://docs.rs/jrsonnet-evaluator/badge.svg)](https://docs.rs/jrsonnet-evaluator)5960Jrsonnet is written in rust itself, so just add it as dependency6162### Python6364[![crates.io](https://img.shields.io/pypi/v/rjsonnet)](https://pypi.org/project/rjsonnet/)6566Bindings are created and maintained by @messense6768### C/C++6970Jrsonnet provides a standard `libjsonnet.so` shared library and should work as drop-in replacement for it7172### Other7374WASM bingings are also available, Java bindings (Both JNI and WASM compiled to .class) are in progress7576See [bindings](./bindings/) for more information.7778## Benchmarks7980This is the fastest implementation of jsonnet both according to official benchmarks and real-life cluster configuration templating speed.8182Official benchmark results are available [in this gist](https://gist.github.com/CertainLach/5770d7ad4836066f8e0bd91e823e451b) which may get updated sometimes. It shows tests against Golang, C++ and Scala implementations showing the best performance in all cases.8384You can generate this report via provided nix flake
after · README.md
1# jrsonnet23[![release](https://img.shields.io/github/v/tag/CertainLach/jrsonnet?color=%23fb4934&label=latest%20release&style=for-the-badge)](https://github.com/CertainLach/jrsonnet/releases)4[![license](https://img.shields.io/github/license/CertainLach/jrsonnet?color=%2383a598&label=license&style=for-the-badge)](/LICENSE)5[![opencollective](https://img.shields.io/opencollective/all/jrsonnet?color=%238ec07c&style=for-the-badge)](https://opencollective.com/jrsonnet)67## What is it89[Jsonnet](https://jsonnet.org/) is a data templating language1011This Rust crate implements both jsonnet library and an alternative `jsonnet` executable based on it. For more information see [bindings](#Bindings).1213## Install1415### NixOS1617jrsonnet is packaged in nixpkgs and maintained by @CertainLach1819```sh20nix-env -iA nixpkgs.jrsonnet21```2223### MacOS2425jrsonnet is packaged to brew and maintained by @messense2627```sh28brew install jrsonnet29```3031### Windows/other linux distributions3233You can get latest build of jrsonnet in [releases](https://github.com/CertainLach/jrsonnet/releases)3435### Build from sources3637jrsonnet should build on latest stable Rust version (probally on olders, but there is no MSRV policy provided)3839Debug build will work too, but it is much slower than release4041```42cargo build --release43```4445## Why?4647There already are multiple implementations of this standard implemented in different languages: [C++](https://github.com/google/jsonnet), [Go](https://github.com/google/go-jsonnet/), [Scala](https://github.com/databricks/sjsonnet).4849This implementation shows performance better than all existing implementations. For more information see [benchmarks](./docs/benchmarks.md).5051Also, I wanted to experiment on new syntax features, and jrsonnet implements some of them. For more information see [features](./docs/features.md)5253In the end, it's always fun to implement something in Rust.5455## Bindings5657### Rust5859[![crates.io](https://img.shields.io/crates/v/jrsonnet-evaluator)](https://crates.io/crates/jrsonnet-evaluator)60[![docs.rs](https://docs.rs/jrsonnet-evaluator/badge.svg)](https://docs.rs/jrsonnet-evaluator)6162Jrsonnet is written in rust itself, so just add it as dependency6364### Python6566[![crates.io](https://img.shields.io/pypi/v/rjsonnet)](https://pypi.org/project/rjsonnet/)6768Bindings are created and maintained by @messense6970### C/C++7172Jrsonnet provides a standard `libjsonnet.so` shared library and should work as drop-in replacement for it7374### Other7576WASM bingings are also available, Java bindings (Both JNI and WASM compiled to .class) are in progress7778See [bindings](./bindings/) for more information.
addeddocs/features.mddiffbeforeafterboth
--- /dev/null
+++ b/docs/features.md
@@ -0,0 +1,159 @@
+# Features
+
+Some features, which exists in jrsonnet, but not yet in other implementations.
+
+Any of those features may be enabled during build time using feature flags, i.e: `--feature=exp-destruct`.
+
+## `exp-destruct`
+
+Destructuring assignment, upstream issue: https://github.com/google/jsonnet/issues/307
+
+Destructuring object:
+
+```jsonnet
+local {a: b} = obj; ...
+// Same as
+local b = obj.a; ...
+```
+
+Field name may be omitted:
+
+> However, field name omission looks off here, as currently jsonnet doesn't allows `local a = 1; {a}` as a sugar for `local a = 1; {a: a}`, this causing asymmetry
+
+```jsonnet
+local {a} = obj; ...
+// Same as
+local a = obj.a; ...
+```
+
+Rest of fields may be collected into another object:
+
+```jsonnet
+local {a, ...rest} = obj; ...
+```
+
+And it is possible to set field defaults:
+
+```jsonnet
+local {a = 1} = {};
+
+a == 1
+```
+
+Destructuring arrays:
+
+```jsonnet
+local [a, b, c] = array; ...
+```
+
+Rest of fields in any position may be collected into other array:
+
+```jsonnet
+local [...rest, a] = array; ...
+local [a, ...rest] = array; ...
+local [a, ...rest, b] = array; ...
+```
+
+In case of not needed fields there is `?` (because `_` is not reserved):
+
+```jsonnet
+local [?, b, c] = ["a", "b", "c"]; ...
+```
+
+Recursive destructuring also works:
+
+```jsonnet
+local {a: [{b: {c: d}}]} = {a:[{b:{c:5}}]}; d == 5
+```
+
+Also mutually recursive declaration works:
+
+```jsonnet
+local
+  {a, b, c} = {a: y, b: c, c: x},
+  {x, y, z} = {x: a, y: 2, z: b};
+z == 2
+```
+
+This feature also works in function arguments:
+> It is impossible to reference those parameters using named argument syntax
+
+```jsonnet
+local myFun({a, b, c}) = a + b + c;
+
+myFun({a: 1, b: 2, c: 3})
+```
+
+## `exp-preserve-order`
+
+Object field order preservation during manifestification, upstream issue: https://github.com/google/jsonnet/issues/903
+
+This feature adds a new CLI argument: `--preserve-order`, as well as additional `std.manifest*/std.objectFields*` standard library functions argument `preserve_order`.
+
+Using this argument, it is possible to have same field order in manifestification, as in declaration:
+
+```jsonnet
+std.objectFields({c: 1, b: 2, a: 3}, preserve_order = false) == ['a', 'b', 'c'] # Fields were sorted
+std.manifestJson({c: 1, b: 2, a: 3}, preserve_order = true) == ['c', 'b', 'a'] # Fields were serialized in declaration order
+```
+
+## `exp-object-iteration`
+
+Iteration over object fields in comprehensions, upstream issue: https://github.com/google/jsonnet/issues/543
+
+This feature is not implemented as proposed in upstream, it only yields `[key, value]` arrays per element:
+
+```jsonnet
+{
+    [i[0] + '!']: i[1] + '!'
+    for i in {
+        a: 1,
+        b: 2,
+        c: 3,
+    }
+} == {
+    'a!': '1!',
+    'b!': '2!',
+    'c!': '3!',
+}
+```
+
+However, it may be combined with `exp-destruct`, to implement syntax close to proposed:
+
+```jsonnet
+{
+    [k + '!']: v + '!'
+    for [k, v] in {
+        a: 1,
+        b: 2,
+        c: 3,
+    }
+} == {
+    'a!': '1!',
+    'b!': '2!',
+    'c!': '3!',
+}
+```
+
+Unfortunately, there is no integration with the `exp-preserve-order` feature, fields will be still iterated in sorted order, and using old syntax is required:
+
+```jsonnet
+local obj = {
+    c: 3,
+    b: 2,
+    a: 1,
+};
+
+{
+    [key + '!']: obj[key] + '!'
+    for key in std.objectFields(obj, preserve_order: true)
+} == {
+    'c!': '3!',
+    'b!': '2!',
+    'a!': '1!',
+}
+```
+
+## `exp-more-hashes`
+
+Adds new standard library function: `std.sha256`, upstream issue: https://github.com/google/jsonnet/pull/607