# rust-jsonnet

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

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

Parse the file

```

[warn(unusedmustuse)]

extern crate libc; extern crate jsonnet; use libc::cchar; 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; pub fn ctos(msgbuf : *const cchar)-> String{ let msgstr: &CStr = unsafe { CStr::fromptr(msgbuf) }; let buf: &[u8] = msgstr.tobytes(); let strbuf: &str = str::fromutf8(buf).unwrap(); let msgdata: String = strbuf.toowned(); return msgdata; }

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

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

pub fn evaluatesnippet(){ 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.readtostring(&mut s).unwrap(); let jsontpl : *const cchar = s.asptr() as *const cchar; let json = match Jsonnet::evaluatesnippet(json_tpl) { Ok(json) => json, Err(e) => panic!("{:?}", e) }; println!("{:?}", json); }

fn main() { version(); evaluatefile(); evaluatesnippet(); Jsonnet::destroy(); } ```