#ion #object #notation #intuitive #format #class #serde

ions

ION(s) | 直观对象表示法(序列化/反序列化)ION是一种设计为用户友好、易于上手和易于阅读的数据格式。此库是ION数据格式的serde实现

10个版本

0.1.9 2021年3月23日
0.1.8 2021年3月23日

#14#直观


iont 使用

MIT 协议

22KB
557

ION

# ion(s) | intuitive object notation (ser/deser)
College MIT
Grades {
    Student1 92
    Student2 95
    Student3 93
    Student4 98
}
Classes [
    History
    Math
    Biology
    CS
    Classics
]
#[derive(Serialize, Deserialize, Debug)]
pub struct Docs {
    College: String,
    Grades: Grades,
    Classes: Vec<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Grades {
    Student1: i64,
    Student2: i64,
    Student3: i64,
    Student4: i64,
}

// the current way of deserializing a struct in ion is weird since
// a deserializer hasn't been implemented yet.
// but, since ion and json are similar, ion is transpiled to json
// and can then be deserialized correctly.
// a deserializer is in progress

use std::fs::read_to_string;
use ion::ion_to_json;

fn main() {
    let docs = read_to_string("docs.ion").unwrap();
    let docs = ion_to_json(&docs).unwrap();
    println!("ion as json {}", docs);
    let docs: Docs = serde_json::from_str(&docs).unwrap();
    println!("{:#?}", docs);
}

依赖项

~2.6–3.5MB
~75K SLoC