mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-16 07:36:38 +00:00
Add quickinstall support
This commit is contained in:
parent
b584038d0d
commit
4e0ca0c1c3
5 changed files with 75 additions and 18 deletions
|
@ -1,17 +1,17 @@
|
|||
use std::path::Path;
|
||||
|
||||
pub use gh_release::*;
|
||||
pub use quickinstall::*;
|
||||
|
||||
use crate::PkgMeta;
|
||||
|
||||
mod gh_release;
|
||||
mod quickinstall;
|
||||
|
||||
#[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;
|
||||
async fn new(data: &Data) -> Result<Box<Self>, anyhow::Error> where Self: Sized;
|
||||
|
||||
/// Fetch a package
|
||||
async fn fetch(&self, dst: &Path) -> Result<(), anyhow::Error>;
|
||||
|
@ -21,10 +21,32 @@ pub trait Fetcher {
|
|||
}
|
||||
|
||||
/// Data required to fetch a package
|
||||
#[derive(Debug)]
|
||||
pub struct Data {
|
||||
pub name: String,
|
||||
pub target: String,
|
||||
pub version: String,
|
||||
pub repo: Option<String>,
|
||||
pub meta: PkgMeta,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct MultiFetcher {
|
||||
fetchers: Vec<Box<dyn Fetcher>>,
|
||||
}
|
||||
|
||||
impl MultiFetcher {
|
||||
pub fn add(&mut self, fetcher: Box<dyn Fetcher>) {
|
||||
self.fetchers.push(fetcher);
|
||||
}
|
||||
|
||||
pub async fn first_available(&self) -> Option<&dyn Fetcher> {
|
||||
for fetcher in &self.fetchers {
|
||||
if fetcher.check().await.unwrap_or(false) {
|
||||
return Some(&**fetcher);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue