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
This commit is contained in:
Oliver Schneider 2014-12-03 09:16:00 +01:00
parent 3a325c666d
commit ea6f628709

View File

@ -51,8 +51,7 @@ use std::collections::TreeMap;
use stats::Stats; use stats::Stats;
use getopts::{OptGroup, optflag, optopt}; use getopts::{OptGroup, optflag, optopt};
use regex::Regex; use regex::Regex;
use serialize::{json, Decodable}; use serialize::{json, Decodable, Encodable};
use serialize::json::{Json, ToJson};
use term::Terminal; use term::Terminal;
use term::color::{Color, RED, YELLOW, GREEN, CYAN}; use term::color::{Color, RED, YELLOW, GREEN, CYAN};
@ -1100,17 +1099,6 @@ fn calc_result(desc: &TestDesc, task_succeeded: bool) -> TestResult {
} }
} }
impl ToJson for Metric {
fn to_json(&self) -> json::Json {
let mut map = TreeMap::new();
map.insert("value".to_string(), json::Json::F64(self.value));
map.insert("noise".to_string(), json::Json::F64(self.noise));
json::Json::Object(map)
}
}
impl MetricMap { impl MetricMap {
pub fn new() -> MetricMap { pub fn new() -> MetricMap {
@ -1138,14 +1126,8 @@ impl MetricMap {
pub fn save(&self, p: &Path) -> io::IoResult<()> { pub fn save(&self, p: &Path) -> io::IoResult<()> {
let mut file = try!(File::create(p)); let mut file = try!(File::create(p));
let MetricMap(ref map) = *self; let MetricMap(ref map) = *self;
let mut enc = json::PrettyEncoder::new(&mut file);
// FIXME(pcwalton): Yuck. map.encode(&mut enc)
let mut new_map = TreeMap::new();
for (ref key, ref value) in map.iter() {
new_map.insert(key.to_string(), (*value).clone());
}
new_map.to_json().to_pretty_writer(&mut file)
} }
/// Compare against another MetricMap. Optionally compare all /// Compare against another MetricMap. Optionally compare all