diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-04-28 20:36:08 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-05-07 23:43:39 -0700 |
| commit | ab92ea526d455b402efbccc7160c8aec0237c88f (patch) | |
| tree | 92e748f3e3496a48ac68dd290a0a08aa342740a1 /src/librustdoc/html/markdown.rs | |
| parent | ef6daf9935da103f1b915a5c9904794da79b0b60 (diff) | |
| download | rust-ab92ea526d455b402efbccc7160c8aec0237c88f.tar.gz rust-ab92ea526d455b402efbccc7160c8aec0237c88f.zip | |
std: Modernize the local_data api
This commit brings the local_data api up to modern rust standards with a few key improvements: * The `pop` and `set` methods have been combined into one method, `replace` * The `get_mut` method has been removed. All interior mutability should be done through `RefCell`. * All functionality is now exposed as a method on the keys themselves. Instead of importing std::local_data, you now use "key.replace()" and "key.get()". * All closures have been removed in favor of RAII functionality. This means that get() and get_mut() no long require closures, but rather return Option<SmartPointer> where the smart pointer takes care of relinquishing the borrow and also implements the necessary Deref traits * The modify() function was removed to cut the local_data interface down to its bare essentials (similarly to how RefCell removed set/get). [breaking-change]
Diffstat (limited to 'src/librustdoc/html/markdown.rs')
| -rw-r--r-- | src/librustdoc/html/markdown.rs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 9d6b0ec5517..0141df34a6c 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -27,11 +27,11 @@ #![allow(non_camel_case_types)] use libc; +use std::cell::RefCell; use std::fmt; use std::io; -use std::local_data; -use std::str; use std::slice; +use std::str; use collections::HashMap; use html::toc::TocBuilder; @@ -139,7 +139,7 @@ fn stripped_filtered_line<'a>(s: &'a str) -> Option<&'a str> { } } -local_data_key!(used_header_map: HashMap<~str, uint>) +local_data_key!(used_header_map: RefCell<HashMap<~str, uint>>) pub fn render(w: &mut io::Writer, s: &str, print_toc: bool) -> fmt::Result { extern fn block(ob: *mut hoedown_buffer, text: *hoedown_buffer, @@ -216,15 +216,12 @@ pub fn render(w: &mut io::Writer, s: &str, print_toc: bool) -> fmt::Result { let opaque = unsafe { &mut *((*opaque).opaque as *mut MyOpaque) }; // Make sure our hyphenated ID is unique for this page - let id = local_data::get_mut(used_header_map, |map| { - let map = map.unwrap(); - match map.find_mut(&id) { - None => {} - Some(a) => { *a += 1; return format!("{}-{}", id, *a - 1) } - } - map.insert(id.clone(), 1); - id.clone() - }); + let map = used_header_map.get().unwrap(); + let id = match map.borrow_mut().find_mut(&id) { + None => id, + Some(a) => { *a += 1; format!("{}-{}", id, *a - 1) } + }; + map.borrow_mut().insert(id.clone(), 1); let sec = match opaque.toc_builder { Some(ref mut builder) => { @@ -348,7 +345,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) { /// used at the beginning of rendering an entire HTML page to reset from the /// previous state (if any). pub fn reset_headers() { - local_data::set(used_header_map, HashMap::new()) + used_header_map.replace(Some(RefCell::new(HashMap::new()))); } impl<'a> fmt::Show for Markdown<'a> { |
