Skip to content

Commit 495ffc2

Browse files
FSMaxBjplatte
authored andcommitted
Manually implement serialize to get things working with 1.46 again
1 parent b074c3f commit 495ffc2

3 files changed

Lines changed: 30 additions & 15 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ categories = ["no-std"]
1313
version = "1.0"
1414
optional = true
1515
default-features = false
16-
features = ["derive"]
1716

1817
[features]
1918
float_deserialize = ["serde"]

src/int.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ use core::{
55
str::FromStr,
66
};
77

8-
#[cfg(feature = "serde")]
9-
use serde::{
10-
de::{Error as _, Unexpected},
11-
Deserialize, Deserializer, Serialize,
12-
};
13-
148
use crate::{
159
error::{ParseIntError, ParseIntErrorKind, TryFromIntError},
1610
UInt, MAX_SAFE_UINT,
1711
};
12+
#[cfg(feature = "serde")]
13+
use serde::{
14+
de::{Error as _, Unexpected},
15+
Deserialize, Deserializer, Serialize, Serializer,
16+
};
1817

1918
/// The largest integer value that can be represented exactly by an f64.
2019
pub const MAX_SAFE_INT: i64 = 0x001F_FFFF_FFFF_FFFF;
@@ -23,7 +22,6 @@ pub const MIN_SAFE_INT: i64 = -MAX_SAFE_INT;
2322

2423
/// An integer limited to the range of integers that can be represented exactly by an f64.
2524
#[derive(Clone, Copy, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
26-
#[cfg_attr(feature = "serde", derive(Serialize))]
2725
pub struct Int(i64);
2826

2927
impl Int {
@@ -612,6 +610,16 @@ impl<'de> Deserialize<'de> for Int {
612610
}
613611
}
614612

613+
#[cfg(feature = "serde")]
614+
impl Serialize for Int {
615+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
616+
where
617+
S: Serializer,
618+
{
619+
serializer.serialize_newtype_struct("Int", &self.0)
620+
}
621+
}
622+
615623
#[cfg(test)]
616624
mod tests {
617625
use super::Int;

src/uint.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,22 @@ use core::{
55
str::FromStr,
66
};
77

8-
#[cfg(feature = "serde")]
9-
use serde::{
10-
de::{Error as _, Unexpected},
11-
Deserialize, Deserializer, Serialize,
12-
};
13-
148
use crate::{
159
error::{ParseIntError, ParseIntErrorKind, TryFromIntError},
1610
MAX_SAFE_INT,
1711
};
12+
#[cfg(feature = "serde")]
13+
use serde::{
14+
de::{Error as _, Unexpected},
15+
Deserialize, Deserializer, Serialize, Serializer,
16+
};
1817

1918
/// The same as `MAX_SAFE_INT`, but with `u64` as the type.
2019
pub const MAX_SAFE_UINT: u64 = 0x001F_FFFF_FFFF_FFFF;
2120

2221
/// An integer limited to the range of non-negative integers that can be represented exactly by an
2322
/// f64.
2423
#[derive(Clone, Copy, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
25-
#[cfg_attr(feature = "serde", derive(Serialize))]
2624
pub struct UInt(u64);
2725

2826
impl UInt {
@@ -603,6 +601,16 @@ impl<'de> Deserialize<'de> for UInt {
603601
}
604602
}
605603

604+
#[cfg(feature = "serde")]
605+
impl Serialize for UInt {
606+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
607+
where
608+
S: Serializer,
609+
{
610+
serializer.serialize_newtype_struct("UInt", &self.0)
611+
}
612+
}
613+
606614
#[cfg(test)]
607615
mod tests {
608616
use super::{UInt, MAX_SAFE_UINT};

0 commit comments

Comments
 (0)