Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FullVersion a superset of Version #70

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions src/async_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,23 +310,8 @@ impl Client {
async fn full_version(&self, version: Version) -> Result<FullVersion, Error> {
let authors_fut = self.crate_authors(&version.crate_name, &version.num);
let deps_fut = self.crate_dependencies(&version.crate_name, &version.num);

try_join!(authors_fut, deps_fut).map(|(authors, deps)| FullVersion {
created_at: version.created_at,
updated_at: version.updated_at,
dl_path: version.dl_path,
downloads: version.downloads,
features: version.features,
id: version.id,
num: version.num,
yanked: version.yanked,
license: version.license,
links: version.links,
readme_path: version.readme_path,

author_names: authors.names,
dependencies: deps,
})
try_join!(authors_fut, deps_fut)
.map(|(authors, deps)| FullVersion::from_parts(version, authors, deps))
}

/// Retrieve all available information for a crate, including download
Expand Down
19 changes: 1 addition & 18 deletions src/sync_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,24 +208,7 @@ impl SyncClient {
fn full_version(&self, version: Version) -> Result<FullVersion, Error> {
let authors = self.crate_authors(&version.crate_name, &version.num)?;
let deps = self.crate_dependencies(&version.crate_name, &version.num)?;

let v = FullVersion {
created_at: version.created_at,
updated_at: version.updated_at,
dl_path: version.dl_path,
downloads: version.downloads,
features: version.features,
id: version.id,
num: version.num,
yanked: version.yanked,
license: version.license,
links: version.links,
readme_path: version.readme_path,

author_names: authors.names,
dependencies: deps,
};
Ok(v)
Ok(FullVersion::from_parts(version, authors, deps))
}

/// Retrieve all available information for a crate, including download
Expand Down
38 changes: 36 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub struct CratesQuery {
pub(crate) page: u64,
pub(crate) user_id: Option<u64>,
/// Crates.io category name.
/// See https://crates.io/categories
/// See <https://crates.io/categories>
/// NOTE: requires lower-case dash-separated categories, not the pretty
/// titles visible in the listing linked above.
pub(crate) category: Option<String>,
Expand Down Expand Up @@ -219,7 +219,7 @@ impl CratesQueryBuilder {
}

/// Crates.io category name.
/// See https://crates.io/categories
/// See <https://crates.io/categories>
/// NOTE: requires lower-case dash-separated categories, not the pretty
/// titles visible in the listing linked above.
#[must_use]
Expand Down Expand Up @@ -555,6 +555,8 @@ impl ReverseDependencies {
#[derive(Serialize, Deserialize, Debug, Clone)]
#[allow(missing_docs)]
pub struct FullVersion {
#[serde(rename = "crate")]
pub crate_name: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub dl_path: String,
Expand All @@ -566,11 +568,43 @@ pub struct FullVersion {
pub license: Option<String>,
pub readme_path: Option<String>,
pub links: VersionLinks,
pub crate_size: Option<u64>,
pub published_by: Option<User>,
pub rust_version: Option<String>,
#[serde(default)]
pub audit_actions: Vec<AuditAction>,

pub author_names: Vec<String>,
pub dependencies: Vec<Dependency>,
}

impl FullVersion {
/// Creates a [`FullVersion`] from a [`Version`], author names, and dependencies.
pub fn from_parts(version: Version, authors: Authors, dependencies: Vec<Dependency>) -> Self {
FullVersion {
crate_name: version.crate_name,
created_at: version.created_at,
updated_at: version.updated_at,
dl_path: version.dl_path,
downloads: version.downloads,
features: version.features,
id: version.id,
num: version.num,
yanked: version.yanked,
license: version.license,
links: version.links,
readme_path: version.readme_path,
crate_size: version.crate_size,
published_by: version.published_by,
rust_version: version.rust_version,
audit_actions: version.audit_actions,

author_names: authors.names,
dependencies,
}
}
}

/// Complete information for a crate.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[allow(missing_docs)]
Expand Down
Loading