#jsonnet #bindings #string #api #field #error #go-jsonnet

sys jsonnet-go-sys

Rust bindings for the go-jsonnet C API

2 releases

0.1.1+go-jsonnet-v0.20.0 Sep 24, 2024
0.1.0+go-jsonnet-v0.20.0 Sep 16, 2024

#15 in #jsonnet

Download history 31/week @ 2024-09-10 198/week @ 2024-09-17 395/week @ 2024-09-24 235/week @ 2024-10-01 151/week @ 2024-10-08 265/week @ 2024-10-15 192/week @ 2024-10-22

920 downloads per month
Used in jsonnet-go

Apache-2.0

11MB
310K SLoC

Go 255K SLoC // 0.0% comments C++ 39K SLoC // 0.1% comments C 7K SLoC // 0.1% comments Jsonnet 2.5K SLoC // 0.2% comments Python 2K SLoC // 0.1% comments Shell 1.5K SLoC // 0.2% comments Bazel 1K SLoC // 0.0% comments Rust 471 SLoC // 0.0% comments JavaScript 459 SLoC // 0.0% comments Visual Studio Project 328 SLoC SWIG 318 SLoC // 0.3% comments Java 140 SLoC // 0.4% comments Visual Studio Solution 41 SLoC GDB Script 10 SLoC // 0.2% comments

jsonnet-go-sys

This crate provides rust bindings for the C API of the go-jsonnet library.

Building

You will need to have go 1.12+ installed in order to build go-jsonnet. This can be gotten via either,

Example

use std::ffi::CStr;
use jsonnet_go_sys::*;

#[derive(Debug, serde::Deserialize)]
struct Basic {
    field: String,
}

let filename = c"basic.jsonnet";
let jsonnet = c"{ field: std.base64('abcd') }";

let vm = unsafe { jsonnet_make() };

let mut error = 0;
let messageptr = unsafe {
    jsonnet_evaluate_snippet(
        vm,
        filename.as_ptr() as _,
        jsonnet.as_ptr() as _,
        &mut error
    )
};

let message = unsafe { CStr::from_ptr(messageptr) };
let message = message.to_str().unwrap();

if error != 0 {
    panic!("jsonnet evaluation returned an error: {message}");
}

let json: Basic = serde_json::from_str(message).unwrap();
assert_eq!(json.field, "YWJjZA==");

unsafe { jsonnet_realloc(vm, messageptr, 0) };
unsafe { jsonnet_destroy(vm) };

Dependencies