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/format.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/format.rs')
| -rw-r--r-- | src/librustdoc/html/format.rs | 129 |
1 files changed, 60 insertions, 69 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 1e2f89659cd..223f9341b73 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -17,7 +17,6 @@ use std::fmt; use std::io; -use std::local_data; use std::strbuf::StrBuf; use syntax::ast; @@ -206,78 +205,72 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool, generics.push_str(">"); } - // Did someone say rightward-drift? - local_data::get(current_location_key, |loc| { - let loc = loc.unwrap(); - - local_data::get(cache_key, |cache| { - let cache = cache.unwrap(); - let abs_root = root(&**cache, loc.as_slice()); - let rel_root = match path.segments.get(0).name.as_slice() { - "self" => Some("./".to_owned()), - _ => None, - }; - - if print_all { - let amt = path.segments.len() - 1; - match rel_root { - Some(root) => { - let mut root = StrBuf::from_str(root); - for seg in path.segments.slice_to(amt).iter() { - if "super" == seg.name || "self" == seg.name { - try!(write!(w, "{}::", seg.name)); - } else { - root.push_str(seg.name); - root.push_str("/"); - try!(write!(w, "<a class='mod' - href='{}index.html'>{}</a>::", - root.as_slice(), - seg.name)); - } - } - } - None => { - for seg in path.segments.slice_to(amt).iter() { - try!(write!(w, "{}::", seg.name)); - } + let loc = current_location_key.get().unwrap(); + let cache = cache_key.get().unwrap(); + let abs_root = root(&**cache, loc.as_slice()); + let rel_root = match path.segments.get(0).name.as_slice() { + "self" => Some("./".to_owned()), + _ => None, + }; + + if print_all { + let amt = path.segments.len() - 1; + match rel_root { + Some(root) => { + let mut root = StrBuf::from_str(root); + for seg in path.segments.slice_to(amt).iter() { + if "super" == seg.name || "self" == seg.name { + try!(write!(w, "{}::", seg.name)); + } else { + root.push_str(seg.name); + root.push_str("/"); + try!(write!(w, "<a class='mod' + href='{}index.html'>{}</a>::", + root.as_slice(), + seg.name)); } } } - - match info(&**cache) { - // This is a documented path, link to it! - Some((ref fqp, shortty)) if abs_root.is_some() => { - let mut url = StrBuf::from_str(abs_root.unwrap()); - let to_link = fqp.slice_to(fqp.len() - 1); - for component in to_link.iter() { - url.push_str(*component); - url.push_str("/"); - } - match shortty { - item_type::Module => { - url.push_str(*fqp.last().unwrap()); - url.push_str("/index.html"); - } - _ => { - url.push_str(shortty.to_static_str()); - url.push_str("."); - url.push_str(*fqp.last().unwrap()); - url.push_str(".html"); - } - } - - try!(write!(w, "<a class='{}' href='{}' title='{}'>{}</a>", - shortty, url, fqp.connect("::"), last.name)); + None => { + for seg in path.segments.slice_to(amt).iter() { + try!(write!(w, "{}::", seg.name)); } + } + } + } + match info(&**cache) { + // This is a documented path, link to it! + Some((ref fqp, shortty)) if abs_root.is_some() => { + let mut url = StrBuf::from_str(abs_root.unwrap()); + let to_link = fqp.slice_to(fqp.len() - 1); + for component in to_link.iter() { + url.push_str(*component); + url.push_str("/"); + } + match shortty { + item_type::Module => { + url.push_str(*fqp.last().unwrap()); + url.push_str("/index.html"); + } _ => { - try!(write!(w, "{}", last.name)); + url.push_str(shortty.to_static_str()); + url.push_str("."); + url.push_str(*fqp.last().unwrap()); + url.push_str(".html"); } } - try!(write!(w, "{}", generics.as_slice())); - Ok(()) - }) - }) + + try!(write!(w, "<a class='{}' href='{}' title='{}'>{}</a>", + shortty, url, fqp.connect("::"), last.name)); + } + + _ => { + try!(write!(w, "{}", last.name)); + } + } + try!(write!(w, "{}", generics.as_slice())); + Ok(()) } /// Helper to render type parameters @@ -302,10 +295,8 @@ impl fmt::Show for clean::Type { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { clean::TyParamBinder(id) | clean::Generic(id) => { - local_data::get(cache_key, |cache| { - let m = cache.unwrap(); - f.buf.write(m.typarams.get(&id).as_bytes()) - }) + let m = cache_key.get().unwrap(); + f.buf.write(m.typarams.get(&id).as_bytes()) } clean::ResolvedPath{id, typarams: ref tp, path: ref path} => { try!(resolved_path(f.buf, id, path, false)); |
