fork of https://github.com/rustwasm/wasm-pack for the needs of NextGraph.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
wasm-pack/src/install/krate.rs

30 lines
750 B

use crate::install::Tool;
use anyhow::Result;
use serde::Deserialize;
const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION");
#[derive(Debug, Deserialize)]
pub struct Krate {
pub max_version: String,
}
#[derive(Debug, Deserialize)]
pub struct KrateResponse {
#[serde(rename = "crate")]
pub krate: Krate,
}
impl Krate {
pub fn new(name: &Tool) -> Result<Krate> {
let krate_address = format!("https://crates.io/api/v1/crates/{}", name);
let res = ureq::get(&krate_address)
.set(
"user-agent",
&format!("wasm-pack/{}", VERSION.unwrap_or("unknown")),
)
.call()?;
let kr: KrateResponse = res.into_json()?;
Ok(kr.krate)
}
}