feat(tvix/eval): Implement builtins.fromJSON
Using `serde_json` for parsing JSON here, plus an `impl FromJSON for Value`. The latter is primarily to stay "dependency light" for now - likely going with an actual serde `Deserialize` impl in the future is going to be way better as it allows saving significantly on intermediary allocations. Change-Id: I152a0448ff7c87cf7ebaac927c38912b99de1c18 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6920 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
parent
277c69cbe5
commit
5eb89be682
12 changed files with 123 additions and 13 deletions
|
@ -271,6 +271,11 @@ fn pure_builtins() -> Vec<Builtin> {
|
|||
Ok(res)
|
||||
},
|
||||
),
|
||||
Builtin::new("fromJSON", &[true], |args: Vec<Value>, _: &mut VM| {
|
||||
let json_str = args[0].to_str()?;
|
||||
let json: serde_json::Value = serde_json::from_str(&json_str)?;
|
||||
json.try_into()
|
||||
}),
|
||||
Builtin::new("genList", &[true, true], |args: Vec<Value>, vm: &mut VM| {
|
||||
let len = args[1].as_int()?;
|
||||
(0..len)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue