cmsis_pack/update/
mod.rs

1use anyhow::Error;
2use std::path::PathBuf;
3use tokio::runtime;
4
5use crate::pdsc::Package;
6
7mod download;
8
9use crate::update::download::DownloadContext;
10pub use crate::update::download::{DownloadConfig, DownloadProgress};
11
12type Result<T> = std::result::Result<T, Error>;
13
14/// Flatten a list of Vidx Urls into a list of updated CMSIS packs
15pub fn update<I, P, D>(config: &D, vidx_list: I, progress: P) -> Result<Vec<PathBuf>>
16where
17    I: IntoIterator<Item = String>,
18    P: DownloadProgress,
19    D: DownloadConfig,
20{
21    let rt = runtime::Builder::new_current_thread()
22        .enable_all()
23        .build()?;
24
25    let dl_cntx = DownloadContext::new(config, progress)?;
26    rt.block_on(dl_cntx.update_vidx(vidx_list))
27}
28
29/// Flatten a list of Vidx Urls into a list of updated CMSIS packs
30pub fn install<'a, I, P, D>(config: &'a D, pdsc_list: I, progress: P) -> Result<Vec<PathBuf>>
31where
32    I: IntoIterator<Item = &'a Package>,
33    P: DownloadProgress + 'a,
34    D: DownloadConfig,
35{
36    let rt = runtime::Builder::new_current_thread()
37        .enable_all()
38        .build()?;
39
40    let dl_cntx = DownloadContext::new(config, progress)?;
41    rt.block_on(async { Ok(dl_cntx.download_iterator(pdsc_list).await) })
42}