<commit_before>use std::path::Path;

use env::Env;
use config::WorkMode;
use file_saver::*;

mod doc;
mod function;
mod function_body_chunk;
mod general;
mod object;
mod objects;
mod parameter;
mod record;
mod records;
mod return_value;
mod sys;
mod trait_impls;
pub mod translate_from_glib;
pub mod translate_to_glib;

pub fn generate(env: &Env) {
    match env.config.work_mode {
        WorkMode::Normal => normal_generate(env),
        WorkMode::Sys => sys::generate(env),
        WorkMode::Doc => doc::generate(env),
    }
}

fn normal_generate(env: &Env) {
    let mut mod_rs: Vec<String> = Vec::new();
    let mut traits: Vec<String> = Vec::new();
    let root_path = env.config.target_path.join("src").join("auto");

    objects::generate(env, &root_path, &mut mod_rs, &mut traits);
    records::generate(env, &root_path, &mut mod_rs);

    generate_mod_rs(env, &root_path, mod_rs, traits);
}

pub fn generate_mod_rs(env: &Env, root_path: &Path, mod_rs: Vec<String>, traits: Vec<String>) {
    let path = root_path.join("mod.rs");
    save_to_file(path, env.config.make_backup, |w| {
        try!(general::start_comments(w, &env.config));
        try!(general::write_vec(w, &mod_rs));
        try!(writeln!(w, ""));
        try!(writeln!(w, "pub mod traits {{"));
        try!(general::write_vec(w, &traits));
        writeln!(w, "}}")
    });<commit_msg>Hide `mod traits` from rustdoc<commit_after>use std::path::Path;

use env::Env;
use config::WorkMode;
use file_saver::*;

mod doc;
mod function;
mod function_body_chunk;
mod general;
mod object;
mod objects;
mod parameter;
mod record;
mod records;
mod return_value;
mod sys;
mod trait_impls;
pub mod translate_from_glib;
pub mod translate_to_glib;

pub fn generate(env: &Env) {
    match env.config.work_mode {
        WorkMode::Normal => normal_generate(env),
        WorkMode::Sys => sys::generate(env),
        WorkMode::Doc => doc::generate(env),
    }
}

fn normal_generate(env: &Env) {
    let mut mod_rs: Vec<String> = Vec::new();
    let mut traits: Vec<String> = Vec::new();
    let root_path = env.config.target_path.join("src").join("auto");

    objects::generate(env, &root_path, &mut mod_rs, &mut traits);
    records::generate(env, &root_path, &mut mod_rs);

    generate_mod_rs(env, &root_path, mod_rs, traits);
}

pub fn generate_mod_rs(env: &Env, root_path: &Path, mod_rs: Vec<String>, traits: Vec<String>) {
    let path = root_path.join("mod.rs");
    save_to_file(path, env.config.make_backup, |w| {
        try!(general::start_comments(w, &env.config));
        try!(general::write_vec(w, &mod_rs));
        try!(writeln!(w, ""));
        try!(writeln!(w, "#[doc(hidden)]"));
        try!(writeln!(w, "pub mod traits {{"));
        try!(general::write_vec(w, &traits));
        writeln!(w, "}}")
    });
{'fraction_non_alphanumeric': 0.16965566714490674, 'fraction_numerical': 0.0, 'mean_word_length': 4.213084112149533, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '67777', 'n_tokens_mistral': 984, 'n_tokens_neox': 977, 'n_words': 222}