diff --git a/src/main.rs b/src/main.rs index c53c6dc..0adf4b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -301,7 +301,7 @@ async fn main() -> Result<(), GertError> { posts.push(post); } else { for subreddit in &subreddits { - let subposts = Subreddit::new(subreddit).get_posts(feed, limit, period).await?; + let subposts = Subreddit::new(subreddit, &session).get_posts(feed, limit, period).await?; posts.extend( subposts .into_iter() diff --git a/src/subreddit.rs b/src/subreddit.rs index 6b2692a..16a1712 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -4,19 +4,19 @@ use log::debug; use reqwest::Client; use std::fmt::Write; -pub struct Subreddit { +pub struct Subreddit<'a> { /// Name of subreddit. pub name: String, url: String, - client: Client, + client: &'a Client, } -impl Subreddit { +impl Subreddit<'_> { /// Create a new `Subreddit` instance. - pub fn new(name: &str) -> Subreddit { + pub fn new<'a>(name: &'a str, session: &'a Client) -> Subreddit<'a> { let subreddit_url = format!("https://www.reddit.com/r/{}", name); - Subreddit { name: name.to_owned(), url: subreddit_url, client: Client::new() } + Subreddit { name: name.to_owned(), url: subreddit_url, client:session } } async fn get_feed( @@ -35,8 +35,10 @@ impl Subreddit { if let Some(a) = after { let _ = write!(url, "&after={}", a); } - - Ok(self.client.get(&url.to_owned()).send().await?.json::