add deep diff pd

This commit is contained in:
Pakin 2025-09-05 08:56:21 +07:00
parent 64a7dae017
commit 6ccc6cb779
5 changed files with 67 additions and 53 deletions

View file

@ -25,55 +25,6 @@ let recipe_dir = cfg.get("RECIPE_DIR").unwrap();
---
** Helper functions **
This will be included in the next version. So the following functions may just have to implement by yourself for now.
```rust
use std::collections::HashMap;
use std::fs::File;
use std::io::{self, Error, Read};
/// Get valid country names
fn valid_country_name() -> Vec<&'static str> {
vec!["mys", "sgp", "aus", "tha", "hkg", "dubai", "uae"]
}
/// Get latest versions of recipes
fn grep_latest_versions(dir_path: &str) -> Result<HashMap<String, usize>, io::Error> {
let mut vs = HashMap::new();
// open dir
let entries = std::fs::read_dir(dir_path)?
.map(|res| res.map(|e| e.path()))
.collect::<Result<Vec<_>, io::Error>>()?;
for e in entries {
let path = e.clone().to_str().unwrap().to_string();
let mut cl_path = path.clone();
let path_split = path.split("/").collect::<Vec<&str>>();
let dir_name = path_split[path_split.len() - 1];
if valid_country_name().contains(&dir_name) {
cl_path.push_str("/version");
// read filename
let mut file = File::open(cl_path)?;
let mut data = String::new();
file.read_to_string(&mut data).unwrap();
vs.insert(dir_name.to_string(), data.parse::<usize>().unwrap());
}
// expect dir with country
}
Ok(vs)
}
```
### Get recipe from specific country (latest)
```rust
...