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(
|
||||
serde_value::ValueDeserializer::<D::Error>::new(value.clone()),
|
||||
) {
|
||||
return if w.workspace {
|
||||
Ok(InheritableField::Inherit(w))
|
||||
} else {
|
||||
Err(de::Error::custom("`workspace` cannot be false"))
|
||||
};
|
||||
return Ok(InheritableField::Inherit(w));
|
||||
}
|
||||
BTreeMap::deserialize(serde_value::ValueDeserializer::<D::Error>::new(value))
|
||||
.map(InheritableField::Value)
|
||||
|
@ -424,13 +420,14 @@ impl<'de> de::Deserialize<'de> for InheritableBtreeMap {
|
|||
#[derive(Deserialize, Serialize, Copy, Clone, Debug)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct TomlInheritedField {
|
||||
#[serde(deserialize_with = "bool_no_false")]
|
||||
workspace: bool,
|
||||
workspace: WorkspaceValue,
|
||||
}
|
||||
|
||||
impl TomlInheritedField {
|
||||
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)]
|
||||
#[serde(untagged)]
|
||||
pub enum InheritableDependency {
|
||||
|
|
Loading…
Reference in a new issue