native_neural_network 0.3.1

Lib no_std Rust for native neural network (.rnn)
Documentation
use std::fs;
use std::path::Path;

fn hex_dump(bytes: &[u8]) -> String {
    let mut out = String::new();

    for (line, chunk) in bytes.chunks(16).enumerate() {
        let offset = line.saturating_mul(16);
        out.push_str(&format!("{offset:08x}: "));

        for i in 0..16 {
            if i < chunk.len() {
                out.push_str(&format!("{:02x} ", chunk[i]));
            } else {
                out.push_str("   ");
            }
            if i == 7 {
                out.push(' ');
            }
        }

        out.push(' ');
        for &byte in chunk {
            let ch = if (0x20..=0x7e).contains(&byte) {
                byte as char
            } else {
                '.'
            };
            out.push(ch);
        }
        out.push('\n');
    }

    out
}

fn scan_file(path: &Path) -> Result<(), String> {
    let rnn_bytes = fs::read(path).map_err(|e| format!("read {} failed: {e}", path.display()))?;
    let rendered = hex_dump(&rnn_bytes);

    let out_path = path.with_extension("txt");
    fs::write(&out_path, rendered.as_bytes())
        .map_err(|e| format!("write {} failed: {e}", out_path.display()))?;

    println!("============================================================");
    println!("file={}", path.display());
    println!("txt={}", out_path.display());

    Ok(())
}

fn main() {
    let files = [
        Path::new("sample_model/f32/sample.rnn"),
        Path::new("sample_model/f64/sample.rnn"),
    ];

    let mut failed = false;
    for file in files {
        if let Err(err) = scan_file(file) {
            eprintln!("{err}");
            failed = true;
        }
    }

    if failed {
        std::process::exit(1);
    }
}