https://github.com/szabodanika/microbin/blob/master/src/util/db_json.rs#L45-L64
if its OK then it tries to read the file and return it:
Ok(_) => {
let reader = BufReader::new(file.unwrap());
let data: Vec<Pasta> = match serde_json::from_reader(reader) {
Ok(t) => t,
_ => Vec::new(),
};
Ok(data)
}
if its Err
then it will create a new DB json file:
Err(_) => {
log::info!("Database file {} not found!", DATABASE_PATH);
save_to_file(&Vec::<Pasta>::new());
log::info!("Database file {} created.", DATABASE_PATH);
load_from_file()
}