mangaplus-parser 0.2.4

Reads mangaplus data from stdin and outputs as JSON
Documentation
extern crate pb_rs;
use pb_rs::types::{Config, FileDescriptor};
use std::path::PathBuf;
use std::io::{BufReader, BufRead, Write};
use std::fs::OpenOptions;
macro_rules! manifest_dir {
    () => {
        ::std::env::var("CARGO_MANIFEST_DIR")
            .expect("CARGO_MANIFEST_DIR is not set")
    }
}
macro_rules! out_dir {
    () => {
        ::std::env::var("OUT_DIR")
            .expect("OUT_DIR is not set")
    }
}
const READER: &str = "/reader.rs";
fn main() {
    println!("{:?}", manifest_dir!());
    let in_file: PathBuf = (manifest_dir!() + "/src/reader.proto").into();
    let out_file: PathBuf = (out_dir!() + READER).into();
    println!("in_file: {:?}, out_file: {:?}", in_file, out_file);
    let cfg = Config {
        in_file,
        out_file,
        single_module: false,
        import_search_path: vec![],
        no_output: false,
        error_cycle: true,
        headers: false,
        dont_use_cow: false,
        custom_includes: vec!["use serde::{Serialize, Deserialize};".to_owned()],
        custom_struct_derive: vec!["Serialize".to_owned(), "Deserialize".to_owned()],
        custom_rpc_generator: Box::new(|_, _| Ok(())),
    };

    FileDescriptor::write_proto(&cfg).expect("written protobuf");
    let out_file = PathBuf::from(out_dir!() + READER);
    println!("{:?}", out_file);
    let file = OpenOptions::new().read(true).open(&out_file).expect("a file out");
    let lines = BufReader::new(file).lines().map(|s| s.expect("line")).collect::<Vec<String>>();
    let mut file_out = OpenOptions::new().write(true).truncate(true).open(&out_file).expect("a writable file");
    for line in lines {
        let new_line = match line.as_str() {
            "#[derive(Debug, PartialEq, Clone)]" => "#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]",
            "#[derive(Debug, PartialEq, Eq, Clone, Copy)]" => "use super::*;\n#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy)]",
            s => s
        };
        writeln!(file_out, "{}", new_line).expect("to write a line");
    }
}