Skip to content

Commit

Permalink
refactor(manifest): Keep struct/impl close for easier viewing
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jan 2, 2025
1 parent 711d6be commit 0414bb5
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,24 @@ pub struct ManifestMetadata {
pub rust_version: Option<RustVersion>,
}

impl ManifestMetadata {
/// Whether the given env var should be tracked by Cargo's dep-info.
pub fn should_track(env_key: &str) -> bool {
let keys = MetadataEnvs::keys();
keys.iter().any(|k| *k == env_key)
}

pub fn env_var<'a>(&'a self, env_key: &str) -> Option<Cow<'a, str>> {
MetadataEnvs::var(self, env_key)
}

pub fn env_vars(&self) -> impl Iterator<Item = (&'static str, Cow<'_, str>)> {
MetadataEnvs::keys()
.iter()
.map(|k| (*k, MetadataEnvs::var(self, k).unwrap()))
}
}

macro_rules! get_metadata_env {
($meta:ident, $field:ident) => {
$meta.$field.as_deref().unwrap_or_default().into()
Expand Down Expand Up @@ -193,24 +211,6 @@ metadata_envs! {
(readme, "CARGO_PKG_README"),
}

impl ManifestMetadata {
/// Whether the given env var should be tracked by Cargo's dep-info.
pub fn should_track(env_key: &str) -> bool {
let keys = MetadataEnvs::keys();
keys.iter().any(|k| *k == env_key)
}

pub fn env_var<'a>(&'a self, env_key: &str) -> Option<Cow<'a, str>> {
MetadataEnvs::var(self, env_key)
}

pub fn env_vars(&self) -> impl Iterator<Item = (&'static str, Cow<'_, str>)> {
MetadataEnvs::keys()
.iter()
.map(|k| (*k, MetadataEnvs::var(self, k).unwrap()))
}
}

#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub enum TargetKind {
Lib(Vec<CrateType>),
Expand Down

0 comments on commit 0414bb5

Please sign in to comment.