mirror of
https://github.com/rust-lang/cargo
synced 2024-08-28 11:50:23 +00:00
Use serde's error message option to avoid implementing Deserialize
.
This commit is contained in:
parent
c9ce0ec40d
commit
54742ce726
|
@ -52,7 +52,7 @@ percent-encoding = "2.0"
|
|||
rustfix = "0.5.0"
|
||||
same-file = "1"
|
||||
semver = { version = "0.10", features = ["serde"] }
|
||||
serde = { version = "1.0.82", features = ["derive"] }
|
||||
serde = { version = "1.0.123", features = ["derive"] }
|
||||
serde_ignored = "0.1.0"
|
||||
serde_json = { version = "1.0.30", features = ["raw_value"] }
|
||||
shell-escape = "0.1.4"
|
||||
|
|
|
@ -419,53 +419,13 @@ impl ser::Serialize for TomlOptLevel {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Eq, PartialEq)]
|
||||
#[serde(untagged)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
|
||||
#[serde(untagged, expecting = "expected a boolean or an integer")]
|
||||
pub enum U32OrBool {
|
||||
U32(u32),
|
||||
Bool(bool),
|
||||
}
|
||||
|
||||
impl<'de> de::Deserialize<'de> for U32OrBool {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: de::Deserializer<'de>,
|
||||
{
|
||||
struct Visitor;
|
||||
|
||||
impl<'de> de::Visitor<'de> for Visitor {
|
||||
type Value = U32OrBool;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter.write_str("a boolean or an integer")
|
||||
}
|
||||
|
||||
fn visit_bool<E>(self, b: bool) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
Ok(U32OrBool::Bool(b))
|
||||
}
|
||||
|
||||
fn visit_i64<E>(self, u: i64) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
Ok(U32OrBool::U32(u as u32))
|
||||
}
|
||||
|
||||
fn visit_u64<E>(self, u: u64) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
Ok(U32OrBool::U32(u as u32))
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_any(Visitor)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone, Debug, Default, Eq, PartialEq)]
|
||||
#[serde(default, rename_all = "kebab-case")]
|
||||
pub struct TomlProfile {
|
||||
|
@ -770,46 +730,13 @@ impl<'de> de::Deserialize<'de> for StringOrVec {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Eq, PartialEq)]
|
||||
#[serde(untagged)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
|
||||
#[serde(untagged, expecting = "expected a boolean or a string")]
|
||||
pub enum StringOrBool {
|
||||
String(String),
|
||||
Bool(bool),
|
||||
}
|
||||
|
||||
impl<'de> de::Deserialize<'de> for StringOrBool {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: de::Deserializer<'de>,
|
||||
{
|
||||
struct Visitor;
|
||||
|
||||
impl<'de> de::Visitor<'de> for Visitor {
|
||||
type Value = StringOrBool;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter.write_str("a boolean or a string")
|
||||
}
|
||||
|
||||
fn visit_bool<E>(self, b: bool) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
Ok(StringOrBool::Bool(b))
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
Ok(StringOrBool::String(s.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_any(Visitor)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug, Serialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum VecStringOrBool {
|
||||
|
|
|
@ -1309,7 +1309,7 @@ fn bad_debuginfo() {
|
|||
error: failed to parse manifest at `[..]`
|
||||
|
||||
Caused by:
|
||||
invalid type: string \"a\", expected a boolean or an integer for [..]
|
||||
expected a boolean or an integer for [..]
|
||||
",
|
||||
)
|
||||
.run();
|
||||
|
@ -1338,7 +1338,7 @@ fn bad_opt_level() {
|
|||
error: failed to parse manifest at `[..]`
|
||||
|
||||
Caused by:
|
||||
invalid type: integer `3`, expected a boolean or a string for key [..]
|
||||
expected a boolean or a string for key [..]
|
||||
",
|
||||
)
|
||||
.run();
|
||||
|
|
Loading…
Reference in a new issue