helper.rs 712 B

1234567891011121314151617181920212223242526
  1. pub fn is_crate_dir(e: &walkdir::DirEntry) -> bool {
  2. let cargo = e.path().file_stem().unwrap().to_str().unwrap().to_string();
  3. cargo == "Cargo".to_string()
  4. }
  5. pub fn is_proto_file(e: &walkdir::DirEntry) -> bool {
  6. if e.path().extension().is_none() {
  7. return false;
  8. }
  9. let ext = e.path().extension().unwrap().to_str().unwrap().to_string();
  10. ext == "proto".to_string()
  11. }
  12. pub fn is_hidden(entry: &walkdir::DirEntry) -> bool {
  13. entry
  14. .file_name()
  15. .to_str()
  16. .map(|s| s.starts_with("."))
  17. .unwrap_or(false)
  18. }
  19. pub fn create_dir_if_not_exist(dir: &str) {
  20. if !std::path::Path::new(&dir).exists() {
  21. std::fs::create_dir_all(&dir).unwrap();
  22. }
  23. }