only_brain/io.rs
1use std::fs::File;
2use std::io::Write;
3use crate::NeuralNetwork;
4
5pub fn dump_model(model: &NeuralNetwork, path: &str) -> Result<(), Box<dyn std::error::Error>> {
6 let encoded = bincode::serialize(model)?;
7
8 let mut file = File::create(path)?;
9 file.write_all(&encoded)?;
10
11 Ok(())
12}
13
14pub fn load_model(path: &str) -> Result<NeuralNetwork, Box<dyn std::error::Error>> {
15 let file = File::open(path)?;
16 let model = bincode::deserialize_from(file)?;
17
18 Ok(model)
19}