1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::BigFloat;
use serde::{Serialize, Serializer};
#[cfg(not(feature = "std"))]
use alloc::string::ToString;
impl Serialize for BigFloat {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(&self.to_string())
}
}
#[cfg(test)]
mod tests {
use serde_json::to_string;
use crate::BigFloat;
#[test]
fn to_json() {
assert_eq!(to_string(&BigFloat::new(0)).unwrap(), "\"0.0\"");
assert_eq!(
to_string(&BigFloat::from_f32(0.3, 64 + 1)).unwrap(),
"\"3.00000011920928955078125e-1\""
);
}
}