mirror of
https://github.com/rust-lang/cargo
synced 2024-08-27 19:29:21 +00:00
refactor(schema): Use dedicated type for 'workspace' field value
This commit is contained in:
parent
4760ef7822
commit
e37a04a9d4
|
@ -410,11 +410,7 @@ impl<'de> de::Deserialize<'de> for InheritableBtreeMap {
|
||||||
if let Ok(w) = TomlInheritedField::deserialize(
|
if let Ok(w) = TomlInheritedField::deserialize(
|
||||||
serde_value::ValueDeserializer::<D::Error>::new(value.clone()),
|
serde_value::ValueDeserializer::<D::Error>::new(value.clone()),
|
||||||
) {
|
) {
|
||||||
return if w.workspace {
|
return Ok(InheritableField::Inherit(w));
|
||||||
Ok(InheritableField::Inherit(w))
|
|
||||||
} else {
|
|
||||||
Err(de::Error::custom("`workspace` cannot be false"))
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
BTreeMap::deserialize(serde_value::ValueDeserializer::<D::Error>::new(value))
|
BTreeMap::deserialize(serde_value::ValueDeserializer::<D::Error>::new(value))
|
||||||
.map(InheritableField::Value)
|
.map(InheritableField::Value)
|
||||||
|
@ -424,13 +420,14 @@ impl<'de> de::Deserialize<'de> for InheritableBtreeMap {
|
||||||
#[derive(Deserialize, Serialize, Copy, Clone, Debug)]
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub struct TomlInheritedField {
|
pub struct TomlInheritedField {
|
||||||
#[serde(deserialize_with = "bool_no_false")]
|
workspace: WorkspaceValue,
|
||||||
workspace: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TomlInheritedField {
|
impl TomlInheritedField {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
TomlInheritedField { workspace: true }
|
TomlInheritedField {
|
||||||
|
workspace: WorkspaceValue,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,6 +446,28 @@ fn bool_no_false<'de, D: de::Deserializer<'de>>(deserializer: D) -> Result<bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug)]
|
||||||
|
#[serde(try_from = "bool")]
|
||||||
|
#[serde(into = "bool")]
|
||||||
|
struct WorkspaceValue;
|
||||||
|
|
||||||
|
impl TryFrom<bool> for WorkspaceValue {
|
||||||
|
type Error = String;
|
||||||
|
fn try_from(other: bool) -> Result<WorkspaceValue, Self::Error> {
|
||||||
|
if other {
|
||||||
|
Ok(WorkspaceValue)
|
||||||
|
} else {
|
||||||
|
Err("`workspace` cannot be false".to_owned())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<WorkspaceValue> for bool {
|
||||||
|
fn from(_: WorkspaceValue) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Clone, Debug)]
|
#[derive(Serialize, Clone, Debug)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum InheritableDependency {
|
pub enum InheritableDependency {
|
||||||
|
|
Loading…
Reference in a new issue