main return more specific type

This commit is contained in:
Troy 2025-01-16 21:21:51 +00:00
parent 8517ac3ac7
commit a6787d0688
Signed by: troy
GPG key ID: DFC06C02ED3B4711
4 changed files with 20 additions and 8 deletions

9
Cargo.lock generated
View file

@ -81,6 +81,12 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "anyhow"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
[[package]]
name = "atom_syndication"
version = "0.12.6"
@ -1025,8 +1031,9 @@ dependencies = [
[[package]]
name = "packard"
version = "0.0.1"
version = "0.0.2"
dependencies = [
"anyhow",
"chrono",
"clap",
"futures",

View file

@ -16,6 +16,7 @@ toml = "0.8.19"
xdg = "2.5.2"
futures = "0.3.31"
indicatif = "0.17.9"
anyhow = "1.0.95"
[profile.dev]
opt-level = 0

View file

@ -1,9 +1,9 @@
use anyhow::{Context, Result};
use chrono::{DateTime, Utc};
use futures::future::join_all;
use indicatif::ProgressBar;
use reqwest::get;
use rss::Channel;
use std::error::Error;
#[derive(Debug)]
pub struct FeedItem {
@ -13,9 +13,14 @@ pub struct FeedItem {
pub pub_date: DateTime<Utc>,
}
async fn fetch_rss(url: &str, pb: &ProgressBar) -> Result<Channel, Box<dyn Error>> {
let response = get(url).await?.text().await?;
let channel = Channel::read_from(response.as_bytes())?;
async fn fetch_rss(url: &str, pb: &ProgressBar) -> Result<Channel> {
let response = get(url)
.await
.context("Failed to send request")?
.text()
.await
.context("Failed to read response text")?;
let channel = Channel::read_from(response.as_bytes()).context("Failed to parse RSS feed")?;
pb.inc(1);
pb.set_message(format!("Processing: {}", channel.title));
Ok(channel)

View file

@ -1,13 +1,12 @@
use indicatif::ProgressStyle;
use std::error::Error;
use tokio;
use tokio::io;
mod config;
mod data;
mod utils;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
async fn main() -> Result<(), io::Error> {
let config = config::validate_config();
let args = config::parse_cli();
let (count, skip_amount, list) = config::collate_values(args, &config);