Skip to content

Commit 9fd8b72

Browse files
committed
fix(toml): Support serializing i128/u128
1 parent 94fc5e0 commit 9fd8b72

2 files changed

Lines changed: 46 additions & 12 deletions

File tree

crates/toml/src/ser/value/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ impl<'d> serde_core::ser::Serializer for ValueSerializer<'d> {
116116
Ok(self.dst)
117117
}
118118

119+
fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error> {
120+
self.dst.value(v)?;
121+
Ok(self.dst)
122+
}
123+
119124
fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error> {
120125
self.dst.value(v)?;
121126
Ok(self.dst)
@@ -136,6 +141,11 @@ impl<'d> serde_core::ser::Serializer for ValueSerializer<'d> {
136141
Ok(self.dst)
137142
}
138143

144+
fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error> {
145+
self.dst.value(v)?;
146+
Ok(self.dst)
147+
}
148+
139149
fn serialize_f32(self, mut v: f32) -> Result<Self::Ok, Self::Error> {
140150
// Discard sign of NaN when serialized using Serde.
141151
//

crates/toml/tests/serde/general.rs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,13 +1246,21 @@ a_b = {value}
12461246
// Through a string equivalent
12471247
println!("to_string");
12481248
assert_data_eq!(
1249-
crate::to_string(&literal).unwrap_err().to_string(),
1250-
str!["i128 is not supported"].raw()
1249+
crate::to_string(&literal).unwrap(),
1250+
str![[r#"
1251+
a_b = -170141183460469231731687303715884105728
1252+
1253+
"#]]
1254+
.raw()
12511255
);
12521256
println!("to_string_pretty");
12531257
assert_data_eq!(
1254-
crate::to_string_pretty(&literal).unwrap_err().to_string(),
1255-
str!["i128 is not supported"].raw()
1258+
crate::to_string_pretty(&literal).unwrap(),
1259+
str![[r#"
1260+
a_b = -170141183460469231731687303715884105728
1261+
1262+
"#]]
1263+
.raw()
12561264
);
12571265
println!("literal, from_str(toml)");
12581266
assert_data_eq!(
@@ -1301,13 +1309,21 @@ a_b = {value}
13011309
// Through a string equivalent
13021310
println!("to_string");
13031311
assert_data_eq!(
1304-
crate::to_string(&literal).unwrap_err().to_string(),
1305-
str!["i128 is not supported"].raw()
1312+
crate::to_string(&literal).unwrap(),
1313+
str![[r#"
1314+
a_b = 170141183460469231731687303715884105727
1315+
1316+
"#]]
1317+
.raw()
13061318
);
13071319
println!("to_string_pretty");
13081320
assert_data_eq!(
1309-
crate::to_string_pretty(&literal).unwrap_err().to_string(),
1310-
str!["i128 is not supported"].raw()
1321+
crate::to_string_pretty(&literal).unwrap(),
1322+
str![[r#"
1323+
a_b = 170141183460469231731687303715884105727
1324+
1325+
"#]]
1326+
.raw()
13111327
);
13121328
println!("literal, from_str(toml)");
13131329
assert_data_eq!(
@@ -1356,13 +1372,21 @@ a_b = {value}
13561372
// Through a string equivalent
13571373
println!("to_string");
13581374
assert_data_eq!(
1359-
crate::to_string(&literal).unwrap_err().to_string(),
1360-
str!["u128 is not supported"].raw()
1375+
crate::to_string(&literal).unwrap(),
1376+
str![[r#"
1377+
a_b = 340282366920938463463374607431768211455
1378+
1379+
"#]]
1380+
.raw()
13611381
);
13621382
println!("to_string_pretty");
13631383
assert_data_eq!(
1364-
crate::to_string_pretty(&literal).unwrap_err().to_string(),
1365-
str!["u128 is not supported"].raw()
1384+
crate::to_string_pretty(&literal).unwrap(),
1385+
str![[r#"
1386+
a_b = 340282366920938463463374607431768211455
1387+
1388+
"#]]
1389+
.raw()
13661390
);
13671391
println!("literal, from_str(toml)");
13681392
assert_data_eq!(

0 commit comments

Comments
 (0)