fix: change method signatures in DbType to take ownership instead of references

This commit is contained in:
monosans
2025-08-05 12:16:28 +03:00
parent 6862dc060b
commit f03f1543fe
2 changed files with 17 additions and 20 deletions
+13 -14
View File
@@ -32,7 +32,7 @@ impl DbType {
}
}
async fn db_path(&self) -> color_eyre::Result<PathBuf> {
async fn db_path(self) -> color_eyre::Result<PathBuf> {
let mut cache_path =
get_cache_path().await.wrap_err("failed to get cache path")?;
match self {
@@ -42,7 +42,7 @@ impl DbType {
Ok(cache_path)
}
async fn etag_path(&self) -> color_eyre::Result<PathBuf> {
async fn etag_path(self) -> color_eyre::Result<PathBuf> {
let mut db_path = self.db_path().await.wrap_err_with(move || {
format!("failed to get {} database path", self.name())
})?;
@@ -51,13 +51,13 @@ impl DbType {
}
async fn save_db(
&self,
self,
mut response: reqwest::Response,
#[cfg(feature = "tui")] tx: tokio::sync::mpsc::UnboundedSender<Event>,
) -> color_eyre::Result<()> {
#[cfg(feature = "tui")]
drop(tx.send(Event::App(AppEvent::IpDbTotal(
*self,
self,
response.content_length(),
))));
@@ -73,18 +73,17 @@ impl DbType {
format!("failed to write to file {}", db_path.display())
})?;
#[cfg(feature = "tui")]
drop(tx.send(Event::App(AppEvent::IpDbDownloaded(
*self,
chunk.len(),
))));
drop(
tx.send(Event::App(AppEvent::IpDbDownloaded(
self,
chunk.len(),
))),
);
}
Ok(())
}
async fn save_etag(
&self,
etag: impl AsRef<[u8]>,
) -> color_eyre::Result<()> {
async fn save_etag(self, etag: impl AsRef<[u8]>) -> color_eyre::Result<()> {
let path = self.etag_path().await?;
tokio::fs::write(&path, etag).await.wrap_err_with(move || {
format!("failed to write to file {}", path.display())
@@ -92,7 +91,7 @@ impl DbType {
}
async fn read_etag(
&self,
self,
) -> color_eyre::Result<Option<reqwest::header::HeaderValue>> {
let path = self.etag_path().await?;
match tokio::fs::read_to_string(&path).await {
@@ -104,7 +103,7 @@ impl DbType {
}
}
async fn remove_etag(&self) -> color_eyre::Result<()> {
async fn remove_etag(self) -> color_eyre::Result<()> {
let path = self.etag_path().await?;
match tokio::fs::remove_file(&path).await {
Ok(()) => Ok(()),
+4 -6
View File
@@ -123,15 +123,13 @@ pub async fn scrape_all(
let proxies = Arc::new(tokio::sync::Mutex::new(HashSet::new()));
let mut join_set = tokio::task::JoinSet::new();
for (proto, sources) in &config.scraping.sources {
for (&proto, sources) in &config.scraping.sources {
#[cfg(feature = "tui")]
drop(
tx.send(Event::App(AppEvent::SourcesTotal(*proto, sources.len()))),
);
drop(tx.send(Event::App(AppEvent::SourcesTotal(proto, sources.len()))));
for source in sources.iter().cloned() {
let config = Arc::clone(&config);
let http_client = http_client.clone();
let proto_copy = *proto;
let proxies = Arc::clone(&proxies);
let token = token.clone();
#[cfg(feature = "tui")]
@@ -142,7 +140,7 @@ pub async fn scrape_all(
res = scrape_one(
config,
http_client,
proto_copy,
proto,
proxies,
source,
#[cfg(feature = "tui")]