This commit is contained in:
39
src/fetching/mod.rs
Normal file
39
src/fetching/mod.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use crate::dance_info::DanceInfo;
|
||||
use crate::fetching::types::DanceInfoError;
|
||||
|
||||
mod scoringdance;
|
||||
mod worldsdc;
|
||||
pub mod types;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[async_trait]
|
||||
pub trait WsdcFetcher: Send + Sync {
|
||||
async fn fetch(&self, id: u32) -> Result<DanceInfo, DanceInfoError>;
|
||||
}
|
||||
|
||||
pub struct WorldsdcFetcher;
|
||||
pub struct ScoringDanceFetcher;
|
||||
|
||||
#[async_trait]
|
||||
impl WsdcFetcher for WorldsdcFetcher {
|
||||
async fn fetch(&self, id: u32) -> Result<DanceInfo, DanceInfoError> {
|
||||
worldsdc::fetch_wsdc_info_wsdc(id).await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl WsdcFetcher for ScoringDanceFetcher {
|
||||
async fn fetch(&self, id: u32) -> Result<DanceInfo, DanceInfoError> {
|
||||
scoringdance::fetch_wsdc_info_scoring_dance(id).await
|
||||
}
|
||||
}
|
||||
|
||||
/// Convenience alias for a shared, dynamic fetcher
|
||||
pub type DynWsdcFetcher = Arc<dyn WsdcFetcher>;
|
||||
|
||||
/// Back-compat helper that uses the `WorldsdcFetcher`.
|
||||
pub async fn fetch_wsdc_info(id: u32) -> Result<DanceInfo, DanceInfoError> {
|
||||
WorldsdcFetcher.fetch(id).await
|
||||
}
|
||||
Reference in New Issue
Block a user