diff options
author | Shing Lyu <shing.lyu@gmail.com> | 2016-10-12 11:47:04 +0800 |
---|---|---|
committer | Shing Lyu <shing.lyu@gmail.com> | 2016-11-07 15:54:07 +0800 |
commit | 8bea421329f584f8394bd9ffe874249d293b8249 (patch) | |
tree | ccb1f2e9e55c488b2a138e10321e51139ea64b97 /components/layout/layout_debug.rs | |
parent | f48b3fe2197a59b29bc711fb1b5496cbb97bd330 (diff) | |
download | servo-8bea421329f584f8394bd9ffe874249d293b8249.tar.gz servo-8bea421329f584f8394bd9ffe874249d293b8249.zip |
Migrated -Z trace-layout to serde_json
Diffstat (limited to 'components/layout/layout_debug.rs')
-rw-r--r-- | components/layout/layout_debug.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/components/layout/layout_debug.rs b/components/layout/layout_debug.rs index 77ed1741add..f98f253881f 100644 --- a/components/layout/layout_debug.rs +++ b/components/layout/layout_debug.rs @@ -10,7 +10,7 @@ use flow; use flow_ref::FlowRef; -use rustc_serialize::json; +use serde_json::{to_string, to_value, Value}; use std::borrow::ToOwned; use std::cell::RefCell; use std::fs::File; @@ -36,20 +36,20 @@ macro_rules! layout_debug_scope( ) ); -#[derive(RustcEncodable)] +#[derive(Serialize)] struct ScopeData { name: String, - pre: String, - post: String, + pre: Value, + post: Value, children: Vec<Box<ScopeData>>, } impl ScopeData { - fn new(name: String, pre: String) -> ScopeData { + fn new(name: String, pre: Value) -> ScopeData { ScopeData { name: name, pre: pre, - post: String::new(), + post: Value::Null, children: vec!(), } } @@ -67,7 +67,7 @@ impl Scope { STATE_KEY.with(|ref r| { match *r.borrow_mut() { Some(ref mut state) => { - let flow_trace = json::encode(&flow::base(&*state.flow_root)).unwrap(); + let flow_trace = to_value(&flow::base(&*state.flow_root)); let data = box ScopeData::new(name.clone(), flow_trace); state.scope_stack.push(data); } @@ -85,7 +85,7 @@ impl Drop for Scope { match *r.borrow_mut() { Some(ref mut state) => { let mut current_scope = state.scope_stack.pop().unwrap(); - current_scope.post = json::encode(&flow::base(&*state.flow_root)).unwrap(); + current_scope.post = to_value(&flow::base(&*state.flow_root)); let previous_scope = state.scope_stack.last_mut().unwrap(); previous_scope.children.push(current_scope); } @@ -109,7 +109,7 @@ pub fn begin_trace(flow_root: FlowRef) { assert!(STATE_KEY.with(|ref r| r.borrow().is_none())); STATE_KEY.with(|ref r| { - let flow_trace = json::encode(&flow::base(&*flow_root)).unwrap(); + let flow_trace = to_value(&flow::base(&*flow_root)); let state = State { scope_stack: vec![box ScopeData::new("root".to_owned(), flow_trace)], flow_root: flow_root.clone(), @@ -125,9 +125,9 @@ pub fn end_trace(generation: u32) { let mut thread_state = STATE_KEY.with(|ref r| r.borrow_mut().take().unwrap()); assert!(thread_state.scope_stack.len() == 1); let mut root_scope = thread_state.scope_stack.pop().unwrap(); - root_scope.post = json::encode(&flow::base(&*thread_state.flow_root)).unwrap(); + root_scope.post = to_value(&flow::base(&*thread_state.flow_root)); - let result = json::encode(&root_scope).unwrap(); + let result = to_string(&root_scope).unwrap(); let mut file = File::create(format!("layout_trace-{}.json", generation)).unwrap(); file.write_all(result.as_bytes()).unwrap(); } |