Use Not::not rather than a custom is_false function (#15645)

The `is_false` function already exists in the standard library, as
`Not::not`; use that in `skip_serializing_if` rather than defining an
`is_false` function.
This commit is contained in:
Weihang Lo 2025-06-09 02:48:06 +00:00 committed by GitHub
commit aed94a893c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 10 deletions

View File

@ -1496,7 +1496,7 @@ impl TomlPlatform {
#[derive(Serialize, Debug, Clone)] #[derive(Serialize, Debug, Clone)]
#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))] #[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
pub struct InheritableLints { pub struct InheritableLints {
#[serde(skip_serializing_if = "is_false")] #[serde(skip_serializing_if = "std::ops::Not::not")]
#[cfg_attr(feature = "unstable-schema", schemars(default))] #[cfg_attr(feature = "unstable-schema", schemars(default))]
pub workspace: bool, pub workspace: bool,
#[serde(flatten)] #[serde(flatten)]
@ -1513,10 +1513,6 @@ impl InheritableLints {
} }
} }
fn is_false(b: &bool) -> bool {
!b
}
impl<'de> Deserialize<'de> for InheritableLints { impl<'de> Deserialize<'de> for InheritableLints {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where where

View File

@ -82,14 +82,10 @@ pub struct NewCrateDependency {
pub artifact: Option<Vec<String>>, pub artifact: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub bindep_target: Option<String>, pub bindep_target: Option<String>,
#[serde(default, skip_serializing_if = "is_false")] #[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub lib: bool, pub lib: bool,
} }
fn is_false(x: &bool) -> bool {
*x == false
}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct User { pub struct User {
pub id: u32, pub id: u32,