Skip to content

Commit

Permalink
fix ron & json serialization of large floats
Browse files Browse the repository at this point in the history
  • Loading branch information
squaaawk authored and knickish committed Jun 22, 2024
1 parent 7cd011f commit 0e22631
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/serde_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ macro_rules! impl_ser_de_json_float {
( $ ty: ident) => {
impl SerJson for $ty {
fn ser_json(&self, _d: usize, s: &mut SerJsonState) {
s.out.push_str(&self.to_string());
s.out.push_str(&format!("{self:?}"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/serde_ron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ macro_rules! impl_ser_de_ron_float {
( $ ty: ident) => {
impl SerRon for $ty {
fn ser_ron(&self, _d: usize, s: &mut SerRonState) {
s.out.push_str(&self.to_string());
s.out.push_str(&format!("{self:?}"));
}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/ser_de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ fn ser_de() {
e: Option<BTreeMap<String, String>>,
f: Option<([u32; 4], String)>,
g: (),
h: f64,
}

let mut map = BTreeMap::new();
map.insert("a".to_string(), "b".to_string());

let test: Test = Test {
a: 1,
b: 2.,
b: 2.718281828459045,
c: Some("asd".to_string()),
d: None,
e: Some(map),
f: Some(([1, 2, 3, 4], "tuple".to_string())),
g: (),
h: 1e30,
};

#[cfg(feature = "binary")]
Expand Down

0 comments on commit 0e22631

Please sign in to comment.