diff --git a/crates/crates-io/lib.rs b/crates/crates-io/lib.rs index 5d8a8c50cc3..e617c5b05f2 100644 --- a/crates/crates-io/lib.rs +++ b/crates/crates-io/lib.rs @@ -102,6 +102,18 @@ pub struct Warnings { pub other: Vec, } +#[derive(Deserialize)] +pub struct VersionDownload { + pub version: i32, + pub downloads: i32, + pub date: String, +} + +#[derive(Deserialize)] +pub struct VersionDownloads { + pub version_downloads: Vec, +} + #[derive(Deserialize)] struct R { ok: bool, @@ -370,6 +382,11 @@ impl Registry { Ok(()) } + pub fn downloads(&mut self, krate: &str, version: &str) -> Result { + let body = self.get(&format!("/crates/{}/{}/downloads", krate, version))?; + Ok(serde_json::from_str::(&body)?) + } + fn put(&mut self, path: &str, b: &[u8]) -> Result { self.handle.put(true)?; self.req(path, Some(b), Auth::Authorized)