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

refactor(toml): Further clean up inheritance #13000

Merged
merged 2 commits into from
Nov 20, 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
7 changes: 0 additions & 7 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,13 +1568,6 @@ impl<T> schema::InheritableField<T> {
}),
}
}

fn as_value(&self) -> Option<&T> {
match self {
schema::InheritableField::Inherit(_) => None,
schema::InheritableField::Value(defined) => Some(defined),
}
}
}

impl schema::InheritableDependency {
Expand Down
23 changes: 22 additions & 1 deletion src/cargo/util/toml/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ pub enum InheritableField<T> {
Inherit(TomlInheritedField),
}

impl<T> InheritableField<T> {
pub fn as_value(&self) -> Option<&T> {
match self {
InheritableField::Inherit(_) => None,
InheritableField::Value(defined) => Some(defined),
}
}
}

//. This already has a `Deserialize` impl from version_trim_whitespace
pub type InheritableSemverVersion = InheritableField<semver::Version>;
impl<'de> de::Deserialize<'de> for InheritableSemverVersion {
Expand Down Expand Up @@ -411,7 +420,19 @@ impl<'de> de::Deserialize<'de> for InheritableBtreeMap {
#[serde(rename_all = "kebab-case")]
pub struct TomlInheritedField {
#[serde(deserialize_with = "bool_no_false")]
pub workspace: bool,
workspace: bool,
}

impl TomlInheritedField {
pub fn new() -> Self {
TomlInheritedField { workspace: true }
}
}

impl Default for TomlInheritedField {
fn default() -> Self {
Self::new()
}
}

fn bool_no_false<'de, D: de::Deserializer<'de>>(deserializer: D) -> Result<bool, D::Error> {
Expand Down