Refactor fetch and install to be more self-contained

This commit is contained in:
Félix Saparelli 2022-02-15 23:58:16 +13:00
parent 81cf2fc526
commit b584038d0d
No known key found for this signature in database
GPG key ID: B948C4BAE44FC474
8 changed files with 268 additions and 116 deletions

30
src/fetchers.rs Normal file
View file

@ -0,0 +1,30 @@
use std::path::Path;
pub use gh_release::*;
use crate::PkgMeta;
mod gh_release;
#[async_trait::async_trait]
pub trait Fetcher {
/// Create a new fetcher from some data
async fn new(data: &Data) -> Result<Self, anyhow::Error>
where
Self: std::marker::Sized;
/// Fetch a package
async fn fetch(&self, dst: &Path) -> Result<(), anyhow::Error>;
/// Check if a package is available for download
async fn check(&self) -> Result<bool, anyhow::Error>;
}
/// Data required to fetch a package
pub struct Data {
pub name: String,
pub target: String,
pub version: String,
pub repo: Option<String>,
pub meta: PkgMeta,
}