rust-jsonnet - The Google Jsonnet( operation data template language) for rust

Overview

rust-jsonnet

====

Crate

rust-jsonnet - The Google Jsonnet( operation data template language) for rust

Google jsonnet documet: (http://google.github.io/jsonnet/doc/)

Parse the file

#[warn(unused_must_use)]
extern crate libc;
extern crate jsonnet;
use libc::c_char;
use std::str;
use std::error::Error;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use std::ffi::CStr;
use std::ffi::CString;
use jsonnet::ffi::command::{ Jsonnet };
pub type JsonnetResult = Result<String, String>;
pub fn ctos(msg_buf : *const c_char)-> String{
    let msg_str: &CStr = unsafe { CStr::from_ptr(msg_buf) };
    let buf: &[u8] = msg_str.to_bytes();
    let str_buf: &str = str::from_utf8(buf).unwrap();
    let msg_data: String = str_buf.to_owned();
    return msg_data;
}

pub fn version(){
    let msg_buf: *const c_char = Jsonnet::version();
    let msg_data: String = ctos(msg_buf);
    println!("{:?}", msg_data);
}

pub fn evaluate_file(){  
    let filename : *const libc::c_char = CString::new("./t.jsonnet") .unwrap().as_ptr();
    let json = match Jsonnet::evaluate_file(filename) {
    Ok(json) => json,
    Err(e) => panic!("{:?}", e)
    };
    println!("{:?}", json);
}

pub fn evaluate_snippet(){
    let path = Path::new("./t.jsonnet");
    let display = path.display();
    let mut file = match File::open(&path) {
    Err(why) => panic!("couldn't open {}: {}", display,
    Error::description(&why)),
    Ok(file) => file,
    };
    let mut s = String::new();
    file.read_to_string(&mut s).unwrap();
    let json_tpl : *const c_char = s.as_ptr() as *const c_char;
    let json = match Jsonnet::evaluate_snippet(json_tpl) {
    Ok(json) => json,
    Err(e) => panic!("{:?}", e)
    };
    println!("{:?}", json);
}

fn main() {
    version();
    evaluate_file();
    evaluate_snippet();
    Jsonnet::destroy();
}
You might also like...
Rust implementation of CRC(16, 32, 64) with support of various standards

crc Rust implementation of CRC(16, 32, 64). MSRV is 1.46. Usage Add crc to Cargo.toml [dependencies] crc = "2.0" Compute CRC use crc::{Crc, Algorithm,

A CSV parser for Rust, with Serde support.

csv A fast and flexible CSV reader and writer for Rust, with support for Serde. Dual-licensed under MIT or the UNLICENSE. Documentation https://docs.r

A HTTP Archive format (HAR) serialization & deserialization library, written in Rust.

har-rs HTTP Archive format (HAR) serialization & deserialization library, written in Rust. Install Add the following to your Cargo.toml file: [depende

A HTML entity encoding library for Rust

A HTML entity encoding library for Rust Example usage All example assume a extern crate htmlescape; and use htmlescape::{relevant functions here}; is

tnetstring serialization library for rust.

TNetStrings: Tagged Netstrings This module implements bindings for the tnetstring serialization format. API let t = tnetstring::str("hello world"); le

A TOML encoding/decoding library for Rust

toml-rs A TOML decoder and encoder for Rust. This library is currently compliant with the v0.5.0 version of TOML. This library will also likely contin

A fast, performant implementation of skip list in Rust.
A fast, performant implementation of skip list in Rust.

Subway A fast, performant implementation of skip list in Rust. A skip list is probabilistic data structure that provides O(log N) search and insertion

A Rust PAC for the RP2040 Microcontroller

rp2040-pac - PAC for Raspberry Pi RP2040 microcontrollers This is a Peripheral Access Crate for the Raspberry Pi RP2040 dual-core Cortex-M0+ microcont

Pure Rust port of CRFsuite: a fast implementation of Conditional Random Fields (CRFs)

crfs-rs Pure Rust port of CRFsuite: a fast implementation of Conditional Random Fields (CRFs) Currently only support prediction, model training is not

Releases(1.8.1)
Owner
Qihoo 360
360 official github
Qihoo 360
pem-rs pem PEM jcreekmore/pem-rs [pem] — A Rust based way to parse and encode PEM-encoded data

pem A Rust library for parsing and encoding PEM-encoded data. Documentation Module documentation with examples Usage Add this to your Cargo.toml: [dep

Jonathan Creekmore 30 Dec 27, 2022
PROST! a Protocol Buffers implementation for the Rust Language

PROST! prost is a Protocol Buffers implementation for the Rust Language. prost generates simple, idiomatic Rust code from proto2 and proto3 files. Com

Dan Burkert 17 Jan 8, 2023
MessagePack implementation for Rust / msgpack.org[Rust]

RMP - Rust MessagePack RMP is a pure Rust MessagePack implementation. This repository consists of three separate crates: the RMP core and two implemen

Evgeny Safronov 840 Dec 30, 2022
A Rust ASN.1 (DER) serializer.

rust-asn1 This is a Rust library for parsing and generating ASN.1 data (DER only). Installation Add asn1 to the [dependencies] section of your Cargo.t

Alex Gaynor 85 Dec 16, 2022
Implementation of Bencode encoding written in rust

Rust Bencode Implementation of Bencode encoding written in rust. Project Status Not in active developement due to lack of time and other priorities. I

Arjan Topolovec 32 Aug 6, 2022
Encoding and decoding support for BSON in Rust

bson-rs Encoding and decoding support for BSON in Rust Index Overview of BSON Format Usage BSON Values BSON Documents Modeling BSON with strongly type

mongodb 304 Dec 30, 2022
Rust library for reading/writing numbers in big-endian and little-endian.

byteorder This crate provides convenience methods for encoding and decoding numbers in either big-endian or little-endian order. Dual-licensed under M

Andrew Gallant 811 Jan 1, 2023
Cap'n Proto for Rust

Cap'n Proto for Rust documentation blog Introduction Cap'n Proto is a type system for distributed systems. With Cap'n Proto, you describe your data an

Cap'n Proto 1.5k Dec 26, 2022
A Gecko-oriented implementation of the Encoding Standard in Rust

encoding_rs encoding_rs an implementation of the (non-JavaScript parts of) the Encoding Standard written in Rust and used in Gecko (starting with Fire

Henri Sivonen 284 Dec 13, 2022
Character encoding support for Rust

Encoding 0.3.0-dev Character encoding support for Rust. (also known as rust-encoding) It is based on WHATWG Encoding Standard, and also provides an ad

Kang Seonghoon 264 Dec 14, 2022