Skip to content

Commit

Permalink
improve CrateInfoSource
Browse files Browse the repository at this point in the history
  • Loading branch information
boozook committed Jun 4, 2024
1 parent 6008903 commit e96cbd4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
6 changes: 4 additions & 2 deletions cargo/src/package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,11 @@ impl<'cfg, 'm> ManifestSource<'cfg, 'm> {
}
}

impl CrateInfoSource for ManifestSource<'_, '_> {
impl<'cfg> CrateInfoSource for ManifestSource<'cfg, '_> {
type Authors = [&'cfg str];

fn name(&self) -> Cow<str> { self.package.name().as_str().into() }
fn authors(&self) -> &[&str] { &self.authors }
fn authors(&self) -> &[&'cfg str] { &self.authors }
fn version(&self) -> Cow<str> { self.package.version().to_string().into() }
fn description(&self) -> Option<Cow<str>> {
self.package
Expand Down
8 changes: 4 additions & 4 deletions cargo/src/utils/cargo/unit_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub mod format {
pub roots: Vec<usize>,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
pub struct Unit {
#[serde(deserialize_with = "deserialize_package_id", alias = "pkg_id")]
pub package_id: PackageId,
Expand All @@ -46,13 +46,13 @@ pub mod format {
#[serde(serialize_with = "CompileMode::serialize")]
#[serde(deserialize_with = "CompileModeProxy::deserialize")]
pub mode: CompileMode,
pub features: Vec<serde_json::Value>,
pub dependencies: Vec<UnitDep>,
// ...
// pub features: Vec<serde_json::Value>,
// pub profile: crate::proc::reader::format::ArtifactProfile,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
pub struct UnitTarget {
pub kind: TargetKind,
#[serde(deserialize_with = "deserialize_crate_types")]
Expand All @@ -62,7 +62,7 @@ pub mod format {
// ...
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
pub struct UnitDep {
pub index: usize,
pub extern_crate_name: String,
Expand Down
1 change: 1 addition & 0 deletions support/build/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(extract_if)]
#![feature(io_error_more)]
#![feature(slice_concat_trait)]
#![cfg_attr(test, feature(assert_matches))]

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion support/build/src/metadata/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl<S: Eq + Hash> Default for AssetsRules<S> {
fn default() -> Self { Self::List(Vec::with_capacity(0)) }
}

impl AssetsRules {
impl<S: Eq + Hash> AssetsRules<S> {
pub fn is_empty(&self) -> bool {
match self {
Self::List(list) => list.is_empty(),
Expand Down
17 changes: 13 additions & 4 deletions support/build/src/metadata/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ use super::format::{AssetsOptions, AssetsRules, Ext, ExtraFields, ExtraValue, Ma


pub trait CrateInfoSource {
type Authors: ?Sized + std::slice::Join<&'static str, Output = String>;

/// Crate name.
fn name(&self) -> Cow<str>;
/// Crate authors.
fn authors(&self) -> &[&str];
fn authors(&self) -> &Self::Authors;
// fn authors(&self) -> &[&str];
/// Crate version (semver).
fn version(&self) -> Cow<str>;
/// Crate description.
Expand All @@ -28,9 +31,11 @@ pub trait CrateInfoSource {

fn manifest_for_crate(&self) -> impl ManifestSourceOptExt {
use super::format::Manifest;
use std::slice::Join;

let author = {
let author = self.authors().join(", ");
// let author = self.authors().join(", ");
let author = Join::join(self.authors(), ", ");
if author.trim().is_empty() {
None
} else {
Expand Down Expand Up @@ -495,8 +500,10 @@ mod tests {

struct CrateInfoNoMeta;
impl CrateInfoSource for CrateInfoNoMeta {
type Authors = [&'static str];

fn name(&self) -> Cow<str> { "Name".into() }
fn authors(&self) -> &[&str] { &["John"] }
fn authors(&self) -> &Self::Authors { &["John"] }
fn version(&self) -> Cow<str> { "0.0.0".into() }
fn description(&self) -> Option<Cow<str>> { None }
fn bins(&self) -> &[&str] { &[SOME_TARGET] }
Expand All @@ -518,8 +525,10 @@ mod tests {

struct CrateInfo;
impl CrateInfoSource for CrateInfo {
type Authors = [&'static str];

fn name(&self) -> Cow<str> { "Crate Name".into() }
fn authors(&self) -> &[&str] { &["John"] }
fn authors(&self) -> &[&'static str] { &["John"] }
fn version(&self) -> Cow<str> { "0.0.0".into() }
fn description(&self) -> Option<Cow<str>> { None }

Expand Down

0 comments on commit e96cbd4

Please sign in to comment.