forked from gnunicorn/rust-multicodec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
48 lines (39 loc) · 1.12 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#![allow(dead_code)]
use convert_case::{Case, Converter};
use serde_derive::Deserialize;
use std::{fs::File, io::Write, path::PathBuf};
#[derive(Debug, Deserialize)]
struct Record {
name: String,
tag: String,
code: String,
status: String,
description: Option<String>,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut pb = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let mut tpb = pb.clone();
// input path
tpb.push("table.csv");
// output path
pb.push("src");
pb.push("table_gen.rs");
let inf = File::open(tpb)?;
let mut f = File::create(pb)?;
let mut rdr = csv::Reader::from_reader(inf);
let conv = Converter::new().to_case(Case::Pascal); //.set_delim("_");
writeln!(f, "build_codec_enum! {{")?;
for row in rdr.deserialize() {
let rec: Record = row?;
writeln!(
f,
"\t{} => ({}, \"{}\"),",
rec.code.trim(),
conv.convert(rec.name.clone()),
rec.name
)?;
}
writeln!(f, "}}")?;
// generate the code for src/table_gen.rs from the multicodecs .csv file
Ok(())
}