Jsonnet 的 RUST 库 rust-jsonnet

码农软件 · 软件分类 · 常用工具包 · 2019-08-16 08:58:53

软件介绍

rust-jsonnet 是 Google Jsonnet 对 rust 操作库.

github:https://github.com/yuduanchen/rust-jsonnet

google jsonnet 官方推荐库列表:http://google.github.io/jsonnet/doc/bindings.html

Google Jsonnet 介绍:

jsonnet 是google发布的新一代json协议。如果说现有的json是一种轻量级的数据交换协议的话,那么jsonnet好比json的2.0版本。赋予了json思想、给予了json注释、引用、算术运算、条件操作符,数组和对象内含引入函数局部变量继承等强大的能力。

hello world:

#[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();
}

本文地址:https://codercto.com/soft/d/12472.html

图解网站分析(修订版)

图解网站分析(修订版)

[日] 小川卓 / 沈麟芸 / 人民邮电出版社 / 2014-10 / 69.00元

本书以图配文,结合实例详细讲解了如何利用从网站上获取的各种数据了解网站的运营状况,如何从数据中攫取最有用的信息,如何优化站点,创造更大的网站价值。本书适合各类网站运营人员阅读。 第1 部分介绍了进行网站分析必备的基础知识。第2 部分详细讲解了如何明确网站现状,发现并改善网站的问题。第3 部分是关于流量获取和网站内渠道优化的问题。第4 部分介绍了一些更加先进的网站分析方法,其中详细讲解了如何分......一起来看看 《图解网站分析(修订版)》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具