eth_avatars/modules/
mod.rs1use async_trait::async_trait;
2
3use crate::{FetchError, Locator, Resource};
4
5pub mod arweave;
6pub mod ethereum;
7pub mod http;
8pub mod ipfs;
9pub mod swarm;
10
11#[async_trait]
12pub trait Fetcher: Send + Sync {
13 type Locator: Locator;
14
15 fn accepts(&self, _locator: &Self::Locator) -> bool {
16 true
17 }
18
19 async fn fetch(&self, locator: &Self::Locator) -> Result<Resource, FetchError>;
20}
21
22#[async_trait]
23pub trait AnyFetcher: Send + Sync {
24 async fn fetch_any(&self, resource: &Resource) -> Option<Result<Resource, FetchError>>;
25}
26
27#[async_trait]
28impl<F: Fetcher> AnyFetcher for F {
29 async fn fetch_any(&self, resource: &Resource) -> Option<Result<Resource, FetchError>> {
30 let locator = F::Locator::of(resource)?;
31
32 self.accepts(locator).then_some(())?;
33
34 Some(self.fetch(locator).await)
35 }
36}