3 个版本

0.1.2 2022年7月3日
0.1.1 2022年7月3日
0.1.0 2021年9月29日

#2536解析器实现

MIT 许可证

78KB
2K SLoC

GCD 解析器和合成器

此库帮助读取/写入 GCD 文件。

读取 GCD 文件

use std::env;
use std::fs::File;
use gcd_rs::parser::Parser;
use gcd_rs::Record;

fn main() {
    //open the gcd file
    let file = File::open("in_file.gcd").unwrap();

    //parser
    let mut parser: Parser<File> = Parser::new(file).unwrap();

    loop {
        //read and print the record until the End is received
        let record = parser.read_record().expect("Unable to read record");
        println!("Record {}", record);
        if let Record::End = record {
            break;
        }
    }
}

写入 GCD 文件

use gcd_rs::composer::Composer;
use gcd_rs::record::text::TextRecord;
use gcd_rs::Record;
use std::env;
use std::fs::File;

fn main() {
    //create the gcd file
    let file = File::create("out_file.gcd").unwrap();

    //composer
    let mut composer: Composer<File> = Composer::new(file).unwrap();

    //write a text record
    composer
        .write_record(&Record::Text(TextRecord::Simple(
            "Sample File".to_string(),
        )))
        .unwrap();
    //write the end record
    composer.write_record(&Record::End).unwrap();
}

依赖项

~1.4–2.2MB
~45K SLoC