Skip to content

Commit ea6f628

Browse files
author
Oliver Schneider
committed
libtest: get rid of dependency to ToJson
deriving encodable + using json::PrettyEncoder removes the only ToJson trait implementation in the rust repository outside of libserialize
1 parent 3a325c6 commit ea6f628

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

src/libtest/lib.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ use std::collections::TreeMap;
5151
use stats::Stats;
5252
use getopts::{OptGroup, optflag, optopt};
5353
use regex::Regex;
54-
use serialize::{json, Decodable};
55-
use serialize::json::{Json, ToJson};
54+
use serialize::{json, Decodable, Encodable};
5655
use term::Terminal;
5756
use term::color::{Color, RED, YELLOW, GREEN, CYAN};
5857

@@ -1100,17 +1099,6 @@ fn calc_result(desc: &TestDesc, task_succeeded: bool) -> TestResult {
11001099
}
11011100
}
11021101

1103-
1104-
impl ToJson for Metric {
1105-
fn to_json(&self) -> json::Json {
1106-
let mut map = TreeMap::new();
1107-
map.insert("value".to_string(), json::Json::F64(self.value));
1108-
map.insert("noise".to_string(), json::Json::F64(self.noise));
1109-
json::Json::Object(map)
1110-
}
1111-
}
1112-
1113-
11141102
impl MetricMap {
11151103

11161104
pub fn new() -> MetricMap {
@@ -1138,14 +1126,8 @@ impl MetricMap {
11381126
pub fn save(&self, p: &Path) -> io::IoResult<()> {
11391127
let mut file = try!(File::create(p));
11401128
let MetricMap(ref map) = *self;
1141-
1142-
// FIXME(pcwalton): Yuck.
1143-
let mut new_map = TreeMap::new();
1144-
for (ref key, ref value) in map.iter() {
1145-
new_map.insert(key.to_string(), (*value).clone());
1146-
}
1147-
1148-
new_map.to_json().to_pretty_writer(&mut file)
1129+
let mut enc = json::PrettyEncoder::new(&mut file);
1130+
map.encode(&mut enc)
11491131
}
11501132

11511133
/// Compare against another MetricMap. Optionally compare all

0 commit comments

Comments
 (0)