From eac47986200b00de3bc94f36c534c2029fa171f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Gr=C3=BCnewald?= Date: Mon, 1 Jan 2024 21:50:57 +0100 Subject: [PATCH] Run cargo fmt --- src/client.rs | 54 ++++++++++++++++++++++++++++----------------------- src/errors.rs | 4 +--- src/lib.rs | 2 +- src/post.rs | 9 ++++----- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/client.rs b/src/client.rs index 2c2a778..94c2acd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,9 +1,7 @@ -use std::io::Write; -use anyhow::Result; -use base64::Engine; -use base64::engine::{GeneralPurpose}; use crate::post::{Post, Posts}; -use reqwest::header::{AUTHORIZATION, HeaderMap, HeaderValue, USER_AGENT}; +use anyhow::Result; +use base64::{engine::GeneralPurpose, Engine}; +use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION, USER_AGENT}; use reqwest::Response; #[derive(Clone, Debug)] @@ -11,7 +9,7 @@ pub struct Client<'a> { auth: Authentication<'a>, useragent: &'a str, host: &'static str, - http_client: reqwest::Client + http_client: reqwest::Client, } impl<'a> Client<'a> { @@ -31,7 +29,7 @@ impl<'a> Client<'a> { auth, useragent, host: "https://e621.net", - http_client + http_client, }) } @@ -40,7 +38,12 @@ impl<'a> Client<'a> { base64_engine.encode(format!("{username}:{apikey}")) } - async fn list_posts_raw(&mut self, limit: Option, tags: Option>, page: Option) -> Result { + async fn list_posts_raw( + &mut self, + limit: Option, + tags: Option>, + page: Option, + ) -> Result { let mut url = url::Url::parse(format!("{}/posts.json", self.host).as_str())?; let mut query_params = Vec::new(); @@ -60,29 +63,32 @@ impl<'a> Client<'a> { url.set_query(Some(&query_params.join("&"))); - Ok(self.http_client.get(url.as_str()) - .send() - .await?) + Ok(self.http_client.get(url.as_str()).send().await?) } - pub async fn list_posts(&mut self, limit: Option, tags: Option>, page: Option) -> Result> { - let res = self.list_posts_raw(limit, tags, page).await?; - let text = res.text().await?; + pub async fn list_posts( + &mut self, + limit: Option, + tags: Option>, + page: Option, + ) -> Result> { + let res = self.list_posts_raw(limit, tags, page).await?; + let text = res.text().await?; - /* - let mut debug_file = std::fs::OpenOptions::new() - .write(true) - .create(true) - .open("./debug.json")?; - debug_file.write_all(text.as_bytes())?; - */ + /* + let mut debug_file = std::fs::OpenOptions::new() + .write(true) + .create(true) + .open("./debug.json")?; + debug_file.write_all(text.as_bytes())?; + */ - Ok(serde_json::from_str::(text.as_str())?.into()) + Ok(serde_json::from_str::(text.as_str())?.into()) } } #[derive(Clone, Copy, Debug)] pub enum Authentication<'a> { - Authorized {username: &'a str, apikey: &'a str}, - Unauthorized + Authorized { username: &'a str, apikey: &'a str }, + Unauthorized, } diff --git a/src/errors.rs b/src/errors.rs index 52bf7ce..5a26c02 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,3 +1 @@ -enum Error { - -} \ No newline at end of file +enum Error {} diff --git a/src/lib.rs b/src/lib.rs index 5682633..4863ac4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,3 @@ pub mod client; -pub mod post; mod errors; +pub mod post; diff --git a/src/post.rs b/src/post.rs index 37ed09f..b750483 100644 --- a/src/post.rs +++ b/src/post.rs @@ -5,7 +5,7 @@ pub type ImageDimension = u64; #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] pub struct Posts { #[serde(alias = "posts")] - inner: Vec + inner: Vec, } impl Into> for Posts { @@ -14,7 +14,6 @@ impl Into> for Posts { } } - #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] pub struct Post { pub id: Id, @@ -32,7 +31,7 @@ pub struct Post { pub has_notes: bool, pub is_favorited: bool, pub change_seq: Option, - pub relationships: PostRelationships + pub relationships: PostRelationships, } #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] @@ -43,7 +42,7 @@ pub struct PostTags { pub character: Vec, pub invalid: Vec, pub meta: Vec, - pub lore: Vec + pub lore: Vec, } #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] @@ -53,7 +52,7 @@ pub struct PostFile { pub ext: String, pub size: FileSize, pub md5: String, - pub url: String + pub url: String, } #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]