1
0
Fork 0
mirror of https://gitlab.com/news-flash/article_scraper.git synced 2025-07-07 16:15:32 +02:00

simplify iterating over dir

This commit is contained in:
Jan Lukas Gernert 2023-04-25 08:58:15 +02:00
parent 309a60c5d0
commit 37d317ad86

View file

@ -43,13 +43,11 @@ impl ConfigCollection {
} }
if let Ok(mut dir) = tokio::fs::read_dir(directory).await { if let Ok(mut dir) = tokio::fs::read_dir(directory).await {
while let Ok(entry) = dir.next_entry().await { while let Ok(Some(entry)) = dir.next_entry().await {
if let Some(entry) = entry { if Util::check_extension(&entry, "txt") {
if Util::check_extension(&entry, "txt") { if let Ok(config) = ConfigEntry::parse_path(&entry.path()).await {
if let Ok(config) = ConfigEntry::parse_path(&entry.path()).await { let file_name = entry.file_name().to_string_lossy().into_owned();
let file_name = entry.file_name().to_string_lossy().into_owned(); user_entries.insert(file_name, config);
user_entries.insert(file_name, config);
}
} }
} }
} }
@ -70,3 +68,15 @@ impl ConfigCollection {
} }
} }
} }
#[cfg(test)]
mod tests {
use std::path::Path;
use super::ConfigCollection;
#[tokio::test]
async fn read_dir() {
let path = Path::new("~/.local/share/news-flash/ftr-site-config");
let _collection = ConfigCollection::parse(Some(path)).await;
}
}