Skip to main content

eth_icons/client/
builder.rs

1use std::sync::Arc;
2
3use crate::{
4    IconClient, IconFetcher, IconSource,
5    modules::{Avara, Blockscout, SafeWallet, Smoldapp, Zerion},
6};
7
8#[derive(Default)]
9pub struct IconClientBuilder {
10    client: Option<reqwest::Client>,
11    sources: Vec<Arc<dyn IconSource>>,
12}
13
14impl IconClientBuilder {
15    pub fn new() -> Self {
16        Self::default()
17    }
18
19    pub fn with_reqwest(mut self, client: reqwest::Client) -> Self {
20        self.client = Some(client);
21        self
22    }
23
24    pub fn with_source<S: IconSource + 'static>(mut self, source: S) -> Self {
25        self.sources.push(Arc::new(source));
26        self
27    }
28
29    pub fn with_shared_source(mut self, source: Arc<dyn IconSource>) -> Self {
30        self.sources.push(source);
31        self
32    }
33
34    pub fn with_defaults(self) -> Self {
35        self.with_source(Blockscout)
36            .with_source(Avara)
37            .with_source(Zerion)
38            .with_source(Smoldapp)
39            .with_source(SafeWallet)
40    }
41
42    pub fn build(self) -> IconClient {
43        IconClient {
44            fetcher: IconFetcher::new(self.client.unwrap_or_default()),
45            sources: self.sources,
46        }
47    }
48}