diff --git a/src/json/ser.rs b/src/json/ser.rs index 54c57726..331fbe4a 100644 --- a/src/json/ser.rs +++ b/src/json/ser.rs @@ -1,4 +1,3 @@ -use std::{f32, f64}; use std::io; use std::num::{Float, FpCategory}; use std::string::FromUtf8Error; @@ -396,7 +395,14 @@ fn fmt_f32_or_null(wr: &mut W, value: f32) -> io::Result<()> { match value.classify() { FpCategory::Nan | FpCategory::Infinite => wr.write_all(b"null"), - _ => wr.write_all(f32::to_str_digits(value, 6).as_bytes()), + _ => { + let s = value.to_string(); + try!(wr.write_all(s.as_bytes())); + if !s.contains('.') { + try!(wr.write_all(b".0")) + } + Ok(()) + } } } @@ -405,7 +411,14 @@ fn fmt_f64_or_null(wr: &mut W, value: f64) -> io::Result<()> { match value.classify() { FpCategory::Nan | FpCategory::Infinite => wr.write_all(b"null"), - _ => wr.write_all(f64::to_str_digits(value, 6).as_bytes()), + _ => { + let s = value.to_string(); + try!(wr.write_all(s.as_bytes())); + if !s.contains('.') { + try!(wr.write_all(b".0")) + } + Ok(()) + } } } diff --git a/src/lib.rs b/src/lib.rs index f5de433c..a1d9d717 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ //! leaving serde to perform roughly the same speed as a hand written serializer for a specific //! type. -#![feature(collections, core, std_misc)] +#![feature(collections, core)] pub use ser::{Serialize, Serializer}; diff --git a/src/ser/impls.rs b/src/ser/impls.rs index 75200cf6..c71a1bd7 100644 --- a/src/ser/impls.rs +++ b/src/ser/impls.rs @@ -1,4 +1,3 @@ -use std::collections::hash_state::HashState; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecMap}; use std::hash::Hash; use std::path; @@ -151,9 +150,8 @@ impl Serialize for BTreeSet } } -impl Serialize for HashSet +impl Serialize for HashSet where T: Serialize + Eq + Hash, - H: HashState, { #[inline] fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> @@ -400,10 +398,9 @@ impl Serialize for BTreeMap } } -impl Serialize for HashMap +impl Serialize for HashMap where K: Serialize + Eq + Hash, V: Serialize, - H: HashState, { #[inline] fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> diff --git a/tests/test_json.rs b/tests/test_json.rs index a87afc76..f7e29791 100644 --- a/tests/test_json.rs +++ b/tests/test_json.rs @@ -101,7 +101,7 @@ fn test_write_i64() { #[test] fn test_write_f64() { let tests = &[ - (3.0, "3"), + (3.0, "3.0"), (3.1, "3.1"), (-1.5, "-1.5"), (0.5, "0.5"),