jsonnet-go-sys

Crates.iojsonnet-go-sys
lib.rsjsonnet-go-sys
version0.1.1+go-jsonnet-v0.20.0
sourcesrc
created_at2024-09-16 23:17:27.945363
updated_at2024-09-24 18:40:40.062016
descriptionRust bindings for the go-jsonnet C API
homepage
repositoryhttps://github.com/swlynch99/jsonnet-go-sys
max_upload_size
id1376977
size13,578,151
Sean Lynch (swlynch99)

documentation

https://docs.rs/jsonnet-go-sys

README

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) };
Commit count: 24

cargo fmt