1
Fork 0

librustdoc: use unboxed closures

This commit is contained in:
Jorge Aparicio 2014-12-09 15:22:19 -05:00
parent 0676c3bf03
commit 888f24969f
2 changed files with 17 additions and 8 deletions

View file

@ -218,10 +218,14 @@ fn resolved_path(w: &mut fmt::Formatter, did: ast::DefId, p: &clean::Path,
})
}
fn path(w: &mut fmt::Formatter, path: &clean::Path, print_all: bool,
root: |&render::Cache, &[String]| -> Option<String>,
info: |&render::Cache| -> Option<(Vec<String> , ItemType)>)
-> fmt::Result
fn path<F, G>(w: &mut fmt::Formatter,
path: &clean::Path,
print_all: bool,
root: F,
info: G)
-> fmt::Result where
F: FnOnce(&render::Cache, &[String]) -> Option<String>,
G: FnOnce(&render::Cache) -> Option<(Vec<String>, ItemType)>,
{
// The generics will get written to both the title and link
let mut generics = String::new();

View file

@ -646,7 +646,9 @@ fn shortty(item: &clean::Item) -> ItemType {
/// static HTML tree.
// FIXME (#9639): The closure should deal with &[u8] instead of &str
// FIXME (#9639): This is too conservative, rejecting non-UTF-8 paths
fn clean_srcpath(src_root: &Path, src: &[u8], f: |&str|) {
fn clean_srcpath<F>(src_root: &Path, src: &[u8], mut f: F) where
F: FnMut(&str),
{
let p = Path::new(src);
// make it relative, if possible
@ -1051,7 +1053,9 @@ impl<'a> Cache {
impl Context {
/// Recurse in the directory structure and change the "root path" to make
/// sure it always points to the top (relatively)
fn recurse<T>(&mut self, s: String, f: |&mut Context| -> T) -> T {
fn recurse<T, F>(&mut self, s: String, f: F) -> T where
F: FnOnce(&mut Context) -> T,
{
if s.len() == 0 {
panic!("Unexpected empty destination: {}", self.current);
}
@ -1131,8 +1135,9 @@ impl Context {
/// all sub-items which need to be rendered.
///
/// The rendering driver uses this closure to queue up more work.
fn item(&mut self, item: clean::Item,
f: |&mut Context, clean::Item|) -> io::IoResult<()> {
fn item<F>(&mut self, item: clean::Item, mut f: F) -> io::IoResult<()> where
F: FnMut(&mut Context, clean::Item),
{
fn render(w: io::File, cx: &Context, it: &clean::Item,
pushname: bool) -> io::IoResult<()> {
info!("Rendering an item to {}", w.path().display());