1
Fork 0

Transition a few fmt::Display impls to functions

This introduces a WithFormatter abstraction that permits one-time
fmt::Display on an arbitrary closure, created via `display_fn`. This
allows us to prevent allocation while still using functions instead of
structs, which are a bit unwieldy to thread arguments through as they
can't easily call each other (and are generally a bit opaque).

The eventual goal here is likely to move us off of the formatting
infrastructure entirely in favor of something more structured, but this
is a good step to move us in that direction as it makes, for example,
passing a context describing current state to the formatting impl much
easier.
This commit is contained in:
Mark Rousskov 2019-08-12 14:36:09 -04:00
parent dafdfee33e
commit edfd5556f1
2 changed files with 56 additions and 52 deletions

View file

@ -2644,19 +2644,19 @@ fn item_module(w: &mut fmt::Formatter<'_>, cx: &Context,
match myitem.inner {
clean::ExternCrateItem(ref name, ref src) => {
use crate::html::format::HRef;
use crate::html::format::anchor;
match *src {
Some(ref src) => {
write!(w, "<tr><td><code>{}extern crate {} as {};",
VisSpace(&myitem.visibility),
HRef::new(myitem.def_id, src),
anchor(myitem.def_id, src),
name)?
}
None => {
write!(w, "<tr><td><code>{}extern crate {};",
VisSpace(&myitem.visibility),
HRef::new(myitem.def_id, name))?
anchor(myitem.def_id, name))?
}
}
write!(w, "</code></td></tr>")?;