Skip to content

Commit ff8df7a

Browse files
authored
Dead code cleanup (#864)
2 parents c77b02f + e3a5f16 commit ff8df7a

File tree

5 files changed

+115
-248
lines changed

5 files changed

+115
-248
lines changed

serde_with/src/content/de.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ use crate::{
2222

2323
/// Used from generated code to buffer the contents of the Deserializer when
2424
/// deserializing untagged enums and internally tagged enums.
25-
///
26-
/// Not public API. Use serde-value instead.
27-
#[derive(Debug, Clone)]
2825
pub(crate) enum Content<'de> {
2926
Bool(bool),
3027

serde_with/src/schemars_0_8.rs

Lines changed: 5 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ use ::schemars_0_8::{
1717
},
1818
JsonSchema,
1919
};
20-
use core::{
21-
mem::ManuallyDrop,
22-
ops::{Deref, DerefMut},
23-
};
2420

2521
//===================================================================
2622
// Trait Definition
@@ -688,9 +684,9 @@ where
688684
};
689685

690686
parents.push(name);
691-
DropGuard::new(parents, |parents| drop(parents.pop()))
687+
utils::DropGuard::new(parents, |parents| drop(parents.pop()))
692688
} else {
693-
DropGuard::unguarded(parents)
689+
utils::DropGuard::unguarded(parents)
694690
};
695691

696692
if let Some(object) = &mut schema.object {
@@ -1063,20 +1059,13 @@ mod timespan {
10631059
// #[non_exhaustive] is not actually necessary here but it should
10641060
// help avoid warnings about semver breakage if this ever changes.
10651061
#[non_exhaustive]
1066-
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
10671062
pub enum TimespanTargetType {
10681063
String,
10691064
F64,
10701065
U64,
10711066
I64,
10721067
}
10731068

1074-
impl TimespanTargetType {
1075-
pub const fn is_signed(self) -> bool {
1076-
!matches!(self, Self::U64)
1077-
}
1078-
}
1079-
10801069
/// Internal helper trait used to constrain which types we implement
10811070
/// `JsonSchemaAs<T>` for.
10821071
pub trait TimespanSchemaTarget<F> {
@@ -1168,7 +1157,7 @@ where
11681157
}
11691158

11701159
impl TimespanTargetType {
1171-
pub(crate) fn to_flexible_schema(self, signed: bool) -> Schema {
1160+
pub(crate) fn into_flexible_schema(self, signed: bool) -> Schema {
11721161
use ::schemars_0_8::schema::StringValidation;
11731162

11741163
let mut number = SchemaObject {
@@ -1198,7 +1187,7 @@ impl TimespanTargetType {
11981187
..Default::default()
11991188
};
12001189

1201-
if self == Self::String {
1190+
if matches!(self, Self::String) {
12021191
number.metadata().write_only = true;
12031192
} else {
12041193
string.metadata().write_only = true;
@@ -1243,7 +1232,7 @@ where
12431232

12441233
fn json_schema(_: &mut SchemaGenerator) -> Schema {
12451234
<T as TimespanSchemaTarget<F>>::TYPE
1246-
.to_flexible_schema(<T as TimespanSchemaTarget<F>>::SIGNED)
1235+
.into_flexible_schema(<T as TimespanSchemaTarget<F>>::SIGNED)
12471236
}
12481237

12491238
fn is_referenceable() -> bool {
@@ -1290,52 +1279,3 @@ forward_duration_schema!(TimestampSecondsWithFrac);
12901279
forward_duration_schema!(TimestampMilliSecondsWithFrac);
12911280
forward_duration_schema!(TimestampMicroSecondsWithFrac);
12921281
forward_duration_schema!(TimestampNanoSecondsWithFrac);
1293-
1294-
//===================================================================
1295-
// Extra internal helper structs
1296-
1297-
struct DropGuard<T, F: FnOnce(T)> {
1298-
value: ManuallyDrop<T>,
1299-
guard: Option<F>,
1300-
}
1301-
1302-
impl<T, F: FnOnce(T)> DropGuard<T, F> {
1303-
pub fn new(value: T, guard: F) -> Self {
1304-
Self {
1305-
value: ManuallyDrop::new(value),
1306-
guard: Some(guard),
1307-
}
1308-
}
1309-
1310-
pub fn unguarded(value: T) -> Self {
1311-
Self {
1312-
value: ManuallyDrop::new(value),
1313-
guard: None,
1314-
}
1315-
}
1316-
}
1317-
1318-
impl<T, F: FnOnce(T)> Deref for DropGuard<T, F> {
1319-
type Target = T;
1320-
1321-
fn deref(&self) -> &Self::Target {
1322-
&self.value
1323-
}
1324-
}
1325-
1326-
impl<T, F: FnOnce(T)> DerefMut for DropGuard<T, F> {
1327-
fn deref_mut(&mut self) -> &mut Self::Target {
1328-
&mut self.value
1329-
}
1330-
}
1331-
1332-
impl<T, F: FnOnce(T)> Drop for DropGuard<T, F> {
1333-
fn drop(&mut self) {
1334-
// SAFETY: value is known to be initialized since we only ever remove it here.
1335-
let value = unsafe { ManuallyDrop::take(&mut self.value) };
1336-
1337-
if let Some(guard) = self.guard.take() {
1338-
guard(value);
1339-
}
1340-
}
1341-
}

serde_with/src/schemars_0_9.rs

Lines changed: 6 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use crate::{
99
formats::{Flexible, Format, PreferMany, PreferOne, Separator, Strict},
1010
prelude::{Schema as WrapSchema, *},
11+
utils::NumberExt as _,
1112
};
1213
use ::schemars_0_9::{json_schema, JsonSchema, Schema, SchemaGenerator};
1314
use alloc::{
@@ -17,10 +18,6 @@ use alloc::{
1718
rc::Rc,
1819
vec::Vec,
1920
};
20-
use core::{
21-
mem::ManuallyDrop,
22-
ops::{Deref, DerefMut},
23-
};
2421
use serde_json::Value;
2522

2623
//===================================================================
@@ -690,9 +687,9 @@ where
690687
};
691688

692689
parents.push(name);
693-
DropGuard::new(parents, |parents| drop(parents.pop()))
690+
utils::DropGuard::new(parents, |parents| drop(parents.pop()))
694691
} else {
695-
DropGuard::unguarded(parents)
692+
utils::DropGuard::unguarded(parents)
696693
};
697694

698695
// We do comparisons here to avoid lifetime conflicts below
@@ -1064,20 +1061,13 @@ mod timespan {
10641061
// #[non_exhaustive] is not actually necessary here but it should
10651062
// help avoid warnings about semver breakage if this ever changes.
10661063
#[non_exhaustive]
1067-
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
10681064
pub enum TimespanTargetType {
10691065
String,
10701066
F64,
10711067
U64,
10721068
I64,
10731069
}
10741070

1075-
impl TimespanTargetType {
1076-
pub const fn is_signed(self) -> bool {
1077-
!matches!(self, Self::U64)
1078-
}
1079-
}
1080-
10811071
/// Internal helper trait used to constrain which types we implement
10821072
/// `JsonSchemaAs<T>` for.
10831073
pub trait TimespanSchemaTarget<F> {
@@ -1172,7 +1162,7 @@ where
11721162
}
11731163

11741164
impl TimespanTargetType {
1175-
pub(crate) fn to_flexible_schema(self, signed: bool) -> Schema {
1165+
pub(crate) fn into_flexible_schema(self, signed: bool) -> Schema {
11761166
let mut number = json_schema!({
11771167
"type": "number"
11781168
});
@@ -1195,7 +1185,7 @@ impl TimespanTargetType {
11951185
}
11961186
});
11971187

1198-
if self == Self::String {
1188+
if matches!(self, Self::String) {
11991189
number
12001190
.ensure_object()
12011191
.insert("writeOnly".into(), true.into());
@@ -1239,7 +1229,7 @@ where
12391229

12401230
fn json_schema(_: &mut SchemaGenerator) -> Schema {
12411231
<T as TimespanSchemaTarget<F>>::TYPE
1242-
.to_flexible_schema(<T as TimespanSchemaTarget<F>>::SIGNED)
1232+
.into_flexible_schema(<T as TimespanSchemaTarget<F>>::SIGNED)
12431233
}
12441234

12451235
fn inline_schema() -> bool {
@@ -1286,77 +1276,3 @@ forward_duration_schema!(TimestampSecondsWithFrac);
12861276
forward_duration_schema!(TimestampMilliSecondsWithFrac);
12871277
forward_duration_schema!(TimestampMicroSecondsWithFrac);
12881278
forward_duration_schema!(TimestampNanoSecondsWithFrac);
1289-
1290-
//===================================================================
1291-
// Extra internal helper structs
1292-
1293-
struct DropGuard<T, F: FnOnce(T)> {
1294-
value: ManuallyDrop<T>,
1295-
guard: Option<F>,
1296-
}
1297-
1298-
impl<T, F: FnOnce(T)> DropGuard<T, F> {
1299-
pub fn new(value: T, guard: F) -> Self {
1300-
Self {
1301-
value: ManuallyDrop::new(value),
1302-
guard: Some(guard),
1303-
}
1304-
}
1305-
1306-
pub fn unguarded(value: T) -> Self {
1307-
Self {
1308-
value: ManuallyDrop::new(value),
1309-
guard: None,
1310-
}
1311-
}
1312-
}
1313-
1314-
impl<T, F: FnOnce(T)> Deref for DropGuard<T, F> {
1315-
type Target = T;
1316-
1317-
fn deref(&self) -> &Self::Target {
1318-
&self.value
1319-
}
1320-
}
1321-
1322-
impl<T, F: FnOnce(T)> DerefMut for DropGuard<T, F> {
1323-
fn deref_mut(&mut self) -> &mut Self::Target {
1324-
&mut self.value
1325-
}
1326-
}
1327-
1328-
impl<T, F: FnOnce(T)> Drop for DropGuard<T, F> {
1329-
fn drop(&mut self) {
1330-
// SAFETY: value is known to be initialized since we only ever remove it here.
1331-
let value = unsafe { ManuallyDrop::take(&mut self.value) };
1332-
1333-
if let Some(guard) = self.guard.take() {
1334-
guard(value);
1335-
}
1336-
}
1337-
}
1338-
1339-
trait NumberExt: Sized {
1340-
fn saturating_sub(&self, count: u64) -> Self;
1341-
}
1342-
1343-
impl NumberExt for serde_json::Number {
1344-
fn saturating_sub(&self, count: u64) -> Self {
1345-
if let Some(v) = self.as_u64() {
1346-
return v.saturating_sub(count).into();
1347-
}
1348-
1349-
if let Some(v) = self.as_i64() {
1350-
if count < i64::MAX as u64 {
1351-
return v.saturating_sub(count as _).into();
1352-
}
1353-
}
1354-
1355-
if let Some(v) = self.as_f64() {
1356-
return serde_json::Number::from_f64(v - (count as f64))
1357-
.expect("saturating_sub resulted in NaN");
1358-
}
1359-
1360-
unreachable!()
1361-
}
1362-
}

0 commit comments

Comments
 (0)