rust-mando 0.1.0

Convert Chinese characters to pinyin with jieba word segmentation
Documentation
//! Build script — compresses `dict/dict.txt.big` → `$OUT_DIR/dict.dat`.
//!
//! Always runs (the Typst target is the only WASM output and always needs the
//! big dictionary). If the source file is missing a clear error is emitted
//! rather than a cryptic `include_bytes!` failure at compile time.
//!
//! Compression uses the C-linked `zstd` crate (level 19, host-only).
//! Decompression at runtime uses `ruzstd` (pure Rust, WASM-safe).

use std::{env, fs, io, path::PathBuf};

fn main() {
    println!("cargo:rerun-if-changed=dict/dict.txt.big");
    println!("cargo:rerun-if-changed=build.rs");

    let src = PathBuf::from("dict/dict.txt.big");
    if !src.exists() {
        println!("cargo:warning=dict/dict.txt.big not found — download it with:");
        println!("cargo:warning=  curl -L https://github.com/fxsjy/jieba/raw/master/extra_dict/dict.txt.big -o dict/dict.txt.big");
        panic!("dict/dict.txt.big missing");
    }

    let out_dir  = PathBuf::from(env::var("OUT_DIR").unwrap());
    let dst      = out_dir.join("dict.dat");

    let raw      = fs::read(&src).expect("failed to read dict/dict.txt.big");
    let mut dst_file = io::BufWriter::new(
        fs::File::create(&dst).expect("failed to create OUT_DIR/dict.dat"),
    );

    zstd::stream::copy_encode(raw.as_slice(), &mut dst_file, 19)
        .expect("zstd compression failed");

    let src_kb = raw.len() / 1024;
    let dst_kb = fs::metadata(&dst).unwrap().len() / 1024;
    println!("cargo:warning=dict.dat: {src_kb} KB → {dst_kb} KB (zstd level 19)");
}