From 7f717d30b72f5f5aa2d8e0ec7482f9e8fa6736ba Mon Sep 17 00:00:00 2001 From: Neshura Date: Thu, 3 Aug 2023 21:38:22 +0200 Subject: [PATCH] Use ? instead of match where appropriate --- src/config/mod.rs | 14 ++++---------- src/main.rs | 24 ++++++------------------ 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 951ee37..cff0599 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -102,12 +102,9 @@ impl Config { let mut post_queue: Vec = vec![]; match self.feeds.iter().map(|feed| { - let res = match CLIENT + let res = CLIENT .get(feed.feed_url.clone()) - .send() { - Ok(data) => data.text().unwrap(), - Err(e) => return Err(e) - }; + .send()?.text()?; let data: FeedData = serde_json::from_str(&res).unwrap(); @@ -281,13 +278,10 @@ impl CommunitiesVector { ..Default::default() }; - let res = match CLIENT + let res = CLIENT .get(base.clone() + "/api/v3/community/list") .query(¶ms) - .send() { - Ok(data) => data.text().unwrap(), - Err(e) => return Err(e) - }; + .send()?.text()?; let site_data: ListCommunitiesResponse = serde_json::from_str(&res).unwrap(); diff --git a/src/main.rs b/src/main.rs index d64a7e6..dc55b0e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,13 +57,10 @@ impl Bot { totp_2fa_token: None, }; - let res = match CLIENT + let res = CLIENT .post(self.config.instance.clone() + "/api/v3/user/login") .json(&login_params) - .send() { - Ok(data) => data, - Err(e) => return Err(e), - }; + .send()?; if res.status() == StatusCode::OK { @@ -84,13 +81,10 @@ impl Bot { /// * `return` : Returns true if Post was succesful, false otherwise #[warn(unused_results)] pub(crate) fn post(&mut self, post_data: CreatePost) -> Result<(), reqwest::Error> { - let res = match CLIENT + let res = CLIENT .post(self.config.instance.clone() + "/api/v3/post") .json(&post_data) - .send() { - Ok(data) => data, - Err(e) => return Err(e) - }; + .send()?; // TODO: process res to get info about if post was successfuly (mostly if jwt token was valid) @@ -106,20 +100,14 @@ impl Bot { println!("Reloading Config"); *prev_time = self.start_time; self.config.load(); - match self.community_ids.load(&self.auth, &self.config.instance) { - Ok(_) => {}, - Err(e) => return Err(e) - }; + self.community_ids.load(&self.auth, &self.config.instance)?; println!("Done!"); } // Start the polling process // Get all feed URLs (use cache) println!("Checking Feeds"); - let post_queue: Vec = match self.config.check_feeds(&mut self.post_history, &self.community_ids, &self.auth) { - Ok(data) => data, - Err(e) => return Err(e) - }; + let post_queue: Vec = self.config.check_feeds(&mut self.post_history, &self.community_ids, &self.auth)?; println!("Done!"); post_queue.iter().for_each(|post| {