From 8b12b313a9abf22b7bf68e27289722877bdb89a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sun, 26 Oct 2025 04:22:11 +0100 Subject: [PATCH] Share `reqwest::Client` in `gallery` example --- examples/gallery/src/civitai.rs | 12 +++++------- examples/gallery/src/main.rs | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/examples/gallery/src/civitai.rs b/examples/gallery/src/civitai.rs index 01e6046b..94ca69c4 100644 --- a/examples/gallery/src/civitai.rs +++ b/examples/gallery/src/civitai.rs @@ -4,7 +4,9 @@ use tokio::task; use std::fmt; use std::io; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; + +static CLIENT: LazyLock = LazyLock::new(reqwest::Client::new); #[derive(Debug, Clone, Deserialize)] pub struct Image { @@ -17,14 +19,12 @@ impl Image { pub const LIMIT: usize = 96; pub async fn list() -> Result, Error> { - let client = reqwest::Client::new(); - #[derive(Deserialize)] struct Response { items: Vec, } - let response: Response = client + let response: Response = CLIENT .get("https://civitai.com/api/v1/images") .query(&[ ("sort", "Most Reactions"), @@ -66,8 +66,6 @@ impl Image { pub fn download(self, size: Size) -> impl Straw { sipper(async move |mut sender| { - let client = reqwest::Client::new(); - if let Size::Thumbnail { width, height } = size { let image = self.clone(); @@ -78,7 +76,7 @@ impl Image { })); } - let bytes = client + let bytes = CLIENT .get(match size { Size::Original => self.url, Size::Thumbnail { width, .. } => self diff --git a/examples/gallery/src/main.rs b/examples/gallery/src/main.rs index cb37e6a1..99bd2cca 100644 --- a/examples/gallery/src/main.rs +++ b/examples/gallery/src/main.rs @@ -588,4 +588,4 @@ fn rounded(theme: &Theme) -> container::Style { container::dark(theme).border(border::rounded(BORDER_RADIUS)) } -const BORDER_RADIUS: u32 = 20; +const BORDER_RADIUS: u32 = 10;