1 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! HTML formatting module
13 //! This module contains a large number of `fmt::Display` implementations for
14 //! various types in `rustdoc::clean`. These implementations all currently
15 //! assume that HTML output is desired, although it may be possible to redesign
16 //! them in the future to instead emit any format desired.
19 use std::iter::repeat;
21 use rustc::hir::def_id::DefId;
25 use clean::{self, PrimitiveType};
26 use core::DocAccessLevels;
27 use html::item_type::ItemType;
29 use html::render::{cache, CURRENT_LOCATION_KEY};
31 /// Helper to render an optional visibility with a space after it (if the
32 /// visibility is preset)
33 #[derive(Copy, Clone)]
34 pub struct VisSpace<'a>(pub &'a Option<clean::Visibility>);
35 /// Similarly to VisSpace, this structure is used to render a function style with a
37 #[derive(Copy, Clone)]
38 pub struct UnsafetySpace(pub hir::Unsafety);
39 /// Similarly to VisSpace, this structure is used to render a function constness
40 /// with a space after it.
41 #[derive(Copy, Clone)]
42 pub struct ConstnessSpace(pub hir::Constness);
43 /// Similar to VisSpace, but used for mutability
44 #[derive(Copy, Clone)]
45 pub struct MutableSpace(pub clean::Mutability);
46 /// Similar to VisSpace, but used for mutability
47 #[derive(Copy, Clone)]
48 pub struct RawMutableSpace(pub clean::Mutability);
49 /// Wrapper struct for emitting type parameter bounds.
50 pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]);
51 /// Wrapper struct for emitting a comma-separated list of items
52 pub struct CommaSep<'a, T: 'a>(pub &'a [T]);
53 pub struct AbiSpace(pub Abi);
55 /// Wrapper struct for properly emitting a method declaration.
56 pub struct Method<'a> {
57 /// The declaration to emit.
58 pub decl: &'a clean::FnDecl,
59 /// The length of the function's "name", used to determine line-wrapping.
61 /// The number of spaces to indent each successive line with, if line-wrapping is necessary.
65 /// Wrapper struct for emitting a where clause from Generics.
66 pub struct WhereClause<'a>{
67 /// The Generics from which to emit a where clause.
68 pub gens: &'a clean::Generics,
69 /// The number of spaces to indent each line with.
71 /// Whether the where clause needs to add a comma and newline after the last bound.
72 pub end_newline: bool,
80 impl<'a> VisSpace<'a> {
81 pub fn get(self) -> &'a Option<clean::Visibility> {
82 let VisSpace(v) = self; v
87 pub fn get(&self) -> hir::Unsafety {
88 let UnsafetySpace(v) = *self; v
93 pub fn get(&self) -> hir::Constness {
94 let ConstnessSpace(v) = *self; v
98 impl<'a, T: fmt::Display> fmt::Display for CommaSep<'a, T> {
99 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
100 for (i, item) in self.0.iter().enumerate() {
101 if i != 0 { write!(f, ", ")?; }
102 fmt::Display::fmt(item, f)?;
108 impl<'a> fmt::Display for TyParamBounds<'a> {
109 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
110 let &TyParamBounds(bounds) = self;
111 for (i, bound) in bounds.iter().enumerate() {
115 fmt::Display::fmt(bound, f)?;
121 impl fmt::Display for clean::GenericParam {
122 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
124 clean::GenericParam::Lifetime(ref lp) => write!(f, "{}", lp),
125 clean::GenericParam::Type(ref tp) => {
126 f.write_str(&tp.name)?;
128 if !tp.bounds.is_empty() {
130 write!(f, ": {:#}", TyParamBounds(&tp.bounds))?;
132 write!(f, ": {}", TyParamBounds(&tp.bounds))?;
136 if let Some(ref ty) = tp.default {
138 write!(f, " = {:#}", ty)?;
140 write!(f, " = {}", ty)?;
150 impl fmt::Display for clean::Generics {
151 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
152 if self.params.is_empty() { return Ok(()) }
154 write!(f, "<{:#}>", CommaSep(&self.params))
156 write!(f, "<{}>", CommaSep(&self.params))
161 impl<'a> fmt::Display for WhereClause<'a> {
162 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
163 let &WhereClause { gens, indent, end_newline } = self;
164 if gens.where_predicates.is_empty() {
167 let mut clause = String::new();
169 clause.push_str(" where");
172 clause.push_str(" <span class=\"where fmt-newline\">where");
174 clause.push_str(" <span class=\"where\">where");
177 for (i, pred) in gens.where_predicates.iter().enumerate() {
181 clause.push_str("<br>");
185 &clean::WherePredicate::BoundPredicate { ref ty, ref bounds } => {
188 clause.push_str(&format!("{:#}: {:#}", ty, TyParamBounds(bounds)));
190 clause.push_str(&format!("{}: {}", ty, TyParamBounds(bounds)));
193 &clean::WherePredicate::RegionPredicate { ref lifetime,
195 clause.push_str(&format!("{}: ", lifetime));
196 for (i, lifetime) in bounds.iter().enumerate() {
198 clause.push_str(" + ");
201 clause.push_str(&format!("{}", lifetime));
204 &clean::WherePredicate::EqPredicate { ref lhs, ref rhs } => {
206 clause.push_str(&format!("{:#} == {:#}", lhs, rhs));
208 clause.push_str(&format!("{} == {}", lhs, rhs));
213 if i < gens.where_predicates.len() - 1 || end_newline {
219 // add a space so stripping <br> tags and breaking spaces still renders properly
223 clause.push_str(" ");
228 clause.push_str("</span>");
229 let padding = repeat(" ").take(indent + 4).collect::<String>();
230 clause = clause.replace("<br>", &format!("<br>{}", padding));
231 clause.insert_str(0, &repeat(" ").take(indent.saturating_sub(1))
232 .collect::<String>());
234 clause.insert_str(0, "<br>");
237 write!(f, "{}", clause)
241 impl fmt::Display for clean::Lifetime {
242 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
243 f.write_str(self.get_ref())?;
248 impl fmt::Display for clean::PolyTrait {
249 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
250 if !self.generic_params.is_empty() {
252 write!(f, "for<{:#}> ", CommaSep(&self.generic_params))?;
254 write!(f, "for<{}> ", CommaSep(&self.generic_params))?;
258 write!(f, "{:#}", self.trait_)
260 write!(f, "{}", self.trait_)
265 impl fmt::Display for clean::TyParamBound {
266 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
268 clean::RegionBound(ref lt) => {
271 clean::TraitBound(ref ty, modifier) => {
272 let modifier_str = match modifier {
273 hir::TraitBoundModifier::None => "",
274 hir::TraitBoundModifier::Maybe => "?",
277 write!(f, "{}{:#}", modifier_str, *ty)
279 write!(f, "{}{}", modifier_str, *ty)
286 impl fmt::Display for clean::PathParameters {
287 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
289 clean::PathParameters::AngleBracketed {
290 ref lifetimes, ref types, ref bindings
292 if !lifetimes.is_empty() || !types.is_empty() || !bindings.is_empty() {
296 f.write_str("<")?;
298 let mut comma = false;
299 for lifetime in lifetimes {
304 write!(f, "{}", *lifetime)?;
312 write!(f, "{:#}", *ty)?;
314 write!(f, "{}", *ty)?;
317 for binding in bindings {
323 write!(f, "{:#}", *binding)?;
325 write!(f, "{}", *binding)?;
331 f.write_str(">")?;
335 clean::PathParameters::Parenthesized { ref inputs, ref output } => {
337 let mut comma = false;
344 write!(f, "{:#}", *ty)?;
346 write!(f, "{}", *ty)?;
350 if let Some(ref ty) = *output {
352 write!(f, " -> {:#}", ty)?;
354 write!(f, " -> {}", ty)?;
363 impl fmt::Display for clean::PathSegment {
364 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
365 f.write_str(&self.name)?;
367 write!(f, "{:#}", self.params)
369 write!(f, "{}", self.params)
374 impl fmt::Display for clean::Path {
375 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
380 for (i, seg) in self.segments.iter().enumerate() {
385 write!(f, "{:#}", seg)?;
387 write!(f, "{}", seg)?;
394 pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
396 if !did.is_local() && !cache.access_levels.is_doc_reachable(did) {
400 let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
401 let (fqp, shortty, mut url) = match cache.paths.get(&did) {
402 Some(&(ref fqp, shortty)) => {
403 (fqp, shortty, repeat("../").take(loc.len()).collect())
406 let &(ref fqp, shortty) = cache.external_paths.get(&did)?;
407 (fqp, shortty, match cache.extern_locations[&did.krate] {
408 (.., render::Remote(ref s)) => s.to_string(),
409 (.., render::Local) => repeat("../").take(loc.len()).collect(),
410 (.., render::Unknown) => return None,
414 for component in &fqp[..fqp.len() - 1] {
415 url.push_str(component);
419 ItemType::Module => {
420 url.push_str(fqp.last().unwrap());
421 url.push_str("/index.html");
424 url.push_str(shortty.css_class());
426 url.push_str(fqp.last().unwrap());
427 url.push_str(".html");
430 Some((url, shortty, fqp.to_vec()))
433 /// Used when rendering a `ResolvedPath` structure. This invokes the `path`
434 /// rendering function with the necessary arguments for linking to a local path.
435 fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
436 print_all: bool, use_absolute: bool) -> fmt::Result {
437 let last = path.segments.last().unwrap();
440 for seg in &path.segments[..path.segments.len() - 1] {
441 write!(w, "{}::", seg.name)?;
445 write!(w, "{:#}{:#}", HRef::new(did, &last.name), last.params)?;
447 let path = if use_absolute {
449 Some((_, _, fqp)) => {
451 fqp[..fqp.len() - 1].join("::"),
452 HRef::new(did, fqp.last().unwrap()))
454 None => format!("{}", HRef::new(did, &last.name)),
457 format!("{}", HRef::new(did, &last.name))
459 write!(w, "{}{}", path, last.params)?;
464 fn primitive_link(f: &mut fmt::Formatter,
465 prim: clean::PrimitiveType,
466 name: &str) -> fmt::Result {
468 let mut needs_termination = false;
470 match m.primitive_locations.get(&prim) {
471 Some(&def_id) if def_id.is_local() => {
472 let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
473 let len = if len == 0 {0} else {len - 1};
474 write!(f, "<a class=\"primitive\" href=\"{}primitive.{}.html\">",
475 repeat("../").take(len).collect::<String>(),
477 needs_termination = true;
480 let loc = match m.extern_locations[&def_id.krate] {
481 (ref cname, _, render::Remote(ref s)) => {
482 Some((cname, s.to_string()))
484 (ref cname, _, render::Local) => {
485 let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
486 Some((cname, repeat("../").take(len).collect::<String>()))
488 (.., render::Unknown) => None,
490 if let Some((cname, root)) = loc {
491 write!(f, "<a class=\"primitive\" href=\"{}{}/primitive.{}.html\">",
495 needs_termination = true;
501 write!(f, "{}", name)?;
502 if needs_termination {
508 /// Helper to render type parameters
509 fn tybounds(w: &mut fmt::Formatter,
510 typarams: &Option<Vec<clean::TyParamBound>>) -> fmt::Result {
512 Some(ref params) => {
513 for param in params {
515 fmt::Display::fmt(param, w)?;
524 pub fn new(did: DefId, text: &'a str) -> HRef<'a> {
525 HRef { did: did, text: text }
529 impl<'a> fmt::Display for HRef<'a> {
530 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
531 match href(self.did) {
532 Some((url, shortty, fqp)) => if !f.alternate() {
533 write!(f, "<a class=\"{}\" href=\"{}\" title=\"{} {}\">{}</a>",
534 shortty, url, shortty, fqp.join("::"), self.text)
536 write!(f, "{}", self.text)
538 _ => write!(f, "{}", self.text),
543 fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt::Result {
545 clean::Generic(ref name) => {
548 clean::ResolvedPath{ did, ref typarams, ref path, is_generic } => {
549 // Paths like T::Output and Self::Output should be rendered with all segments
550 resolved_path(f, did, path, is_generic, use_absolute)?;
551 tybounds(f, typarams)
553 clean::Infer => write!(f, "_"),
554 clean::Primitive(prim) => primitive_link(f, prim, prim.as_str()),
555 clean::BareFunction(ref decl) => {
557 write!(f, "{}{:#}fn{:#}{:#}",
558 UnsafetySpace(decl.unsafety),
560 CommaSep(&decl.generic_params),
563 write!(f, "{}{}", UnsafetySpace(decl.unsafety), AbiSpace(decl.abi))?;
564 primitive_link(f, PrimitiveType::Fn, "fn")?;
565 write!(f, "{}{}", CommaSep(&decl.generic_params), decl.decl)
568 clean::Tuple(ref typs) => {
570 &[] => primitive_link(f, PrimitiveType::Unit, "()"),
572 primitive_link(f, PrimitiveType::Tuple, "(")?;
573 //carry f.alternate() into this display w/o branching manually
574 fmt::Display::fmt(one, f)?;
575 primitive_link(f, PrimitiveType::Tuple, ",)")
578 primitive_link(f, PrimitiveType::Tuple, "(")?;
579 fmt::Display::fmt(&CommaSep(&many), f)?;
580 primitive_link(f, PrimitiveType::Tuple, ")")
584 clean::Slice(ref t) => {
585 primitive_link(f, PrimitiveType::Slice, "[")?;
586 fmt::Display::fmt(t, f)?;
587 primitive_link(f, PrimitiveType::Slice, "]")
589 clean::Array(ref t, ref n) => {
590 primitive_link(f, PrimitiveType::Array, "[")?;
591 fmt::Display::fmt(t, f)?;
592 primitive_link(f, PrimitiveType::Array, &format!("; {}]", n))
594 clean::Never => primitive_link(f, PrimitiveType::Never, "!"),
595 clean::RawPointer(m, ref t) => {
597 clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} => {
599 primitive_link(f, clean::PrimitiveType::RawPointer,
600 &format!("*{}{:#}", RawMutableSpace(m), t))
602 primitive_link(f, clean::PrimitiveType::RawPointer,
603 &format!("*{}{}", RawMutableSpace(m), t))
607 primitive_link(f, clean::PrimitiveType::RawPointer,
608 &format!("*{}", RawMutableSpace(m)))?;
609 fmt::Display::fmt(t, f)
613 clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => {
615 Some(ref l) => format!("{} ", *l),
618 let m = MutableSpace(mutability);
619 let amp = if f.alternate() {
625 clean::Slice(ref bt) => { // BorrowedRef{ ... Slice(T) } is &[T]
627 clean::Generic(_) => {
629 primitive_link(f, PrimitiveType::Slice,
630 &format!("{}{}{}[{:#}]", amp, lt, m, **bt))
632 primitive_link(f, PrimitiveType::Slice,
633 &format!("{}{}{}[{}]", amp, lt, m, **bt))
637 primitive_link(f, PrimitiveType::Slice,
638 &format!("{}{}{}[", amp, lt, m))?;
640 write!(f, "{:#}", **bt)?;
642 write!(f, "{}", **bt)?;
644 primitive_link(f, PrimitiveType::Slice, "]")
648 clean::ResolvedPath { typarams: Some(ref v), .. } if !v.is_empty() => {
649 write!(f, "{}{}{}(", amp, lt, m)?;
650 fmt_type(&ty, f, use_absolute)?;
653 clean::Generic(..) => {
654 primitive_link(f, PrimitiveType::Reference,
655 &format!("{}{}{}", amp, lt, m))?;
656 fmt_type(&ty, f, use_absolute)
659 write!(f, "{}{}{}", amp, lt, m)?;
660 fmt_type(&ty, f, use_absolute)
664 clean::ImplTrait(ref bounds) => {
666 for (i, bound) in bounds.iter().enumerate() {
671 write!(f, "{:#}", *bound)?;
673 write!(f, "{}", *bound)?;
678 clean::QPath { ref name, ref self_type, ref trait_ } => {
679 let should_show_cast = match *trait_ {
680 box clean::ResolvedPath { ref path, .. } => {
681 !path.segments.is_empty() && !self_type.is_self_type()
686 if should_show_cast {
687 write!(f, "<{:#} as {:#}>::", self_type, trait_)?
689 write!(f, "{:#}::", self_type)?
692 if should_show_cast {
693 write!(f, "<{} as {}>::", self_type, trait_)?
695 write!(f, "{}::", self_type)?
699 // It's pretty unsightly to look at `<A as B>::C` in output, and
700 // we've got hyperlinking on our side, so try to avoid longer
701 // notation as much as possible by making `C` a hyperlink to trait
702 // `B` to disambiguate.
704 // FIXME: this is still a lossy conversion and there should probably
705 // be a better way of representing this in general? Most of
706 // the ugliness comes from inlining across crates where
707 // everything comes in as a fully resolved QPath (hard to
709 box clean::ResolvedPath { did, ref typarams, .. } => {
711 Some((ref url, _, ref path)) if !f.alternate() => {
713 "<a class=\"type\" href=\"{url}#{shortty}.{name}\" \
714 title=\"type {path}::{name}\">{name}</a>",
716 shortty = ItemType::AssociatedType,
718 path = path.join("::"))?;
720 _ => write!(f, "{}", name)?,
723 // FIXME: `typarams` are not rendered, and this seems bad?
728 write!(f, "{}", name)
732 clean::Unique(..) => {
733 panic!("should have been cleaned")
738 impl fmt::Display for clean::Type {
739 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
740 fmt_type(self, f, false)
744 fn fmt_impl(i: &clean::Impl,
745 f: &mut fmt::Formatter,
747 use_absolute: bool) -> fmt::Result {
749 write!(f, "impl{:#} ", i.generics)?;
751 write!(f, "impl{} ", i.generics)?;
754 if let Some(ref ty) = i.trait_ {
755 if i.polarity == Some(clean::ImplPolarity::Negative) {
760 fmt::Display::fmt(ty, f)?;
763 clean::ResolvedPath { typarams: None, ref path, is_generic: false, .. } => {
764 let last = path.segments.last().unwrap();
765 fmt::Display::fmt(&last.name, f)?;
766 fmt::Display::fmt(&last.params, f)?;
774 fmt_type(&i.for_, f, use_absolute)?;
776 fmt::Display::fmt(&WhereClause { gens: &i.generics, indent: 0, end_newline: true }, f)?;
780 impl fmt::Display for clean::Impl {
781 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
782 fmt_impl(self, f, true, false)
786 // The difference from above is that trait is not hyperlinked.
787 pub fn fmt_impl_for_trait_page(i: &clean::Impl,
788 f: &mut fmt::Formatter,
789 use_absolute: bool) -> fmt::Result {
790 fmt_impl(i, f, false, use_absolute)
793 impl fmt::Display for clean::Arguments {
794 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
795 for (i, input) in self.values.iter().enumerate() {
796 if !input.name.is_empty() {
797 write!(f, "{}: ", input.name)?;
800 write!(f, "{:#}", input.type_)?;
802 write!(f, "{}", input.type_)?;
804 if i + 1 < self.values.len() { write!(f, ", ")?; }
810 impl fmt::Display for clean::FunctionRetTy {
811 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
813 clean::Return(clean::Tuple(ref tys)) if tys.is_empty() => Ok(()),
814 clean::Return(ref ty) if f.alternate() => write!(f, " -> {:#}", ty),
815 clean::Return(ref ty) => write!(f, " -> {}", ty),
816 clean::DefaultReturn => Ok(()),
821 impl fmt::Display for clean::FnDecl {
822 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
825 write!(f, "({args:#}, ...){arrow:#}", args = self.inputs, arrow = self.output)
827 write!(f, "({args}, ...){arrow}", args = self.inputs, arrow = self.output)
831 write!(f, "({args:#}){arrow:#}", args = self.inputs, arrow = self.output)
833 write!(f, "({args}){arrow}", args = self.inputs, arrow = self.output)
839 impl<'a> fmt::Display for Method<'a> {
840 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
841 let &Method { decl, name_len, indent } = self;
842 let amp = if f.alternate() { "&" } else { "&" };
843 let mut args = String::new();
844 let mut args_plain = String::new();
845 for (i, input) in decl.inputs.values.iter().enumerate() {
847 args.push_str("<br>");
850 if let Some(selfty) = input.to_self() {
852 clean::SelfValue => {
853 args.push_str("self");
854 args_plain.push_str("self");
856 clean::SelfBorrowed(Some(ref lt), mtbl) => {
857 args.push_str(&format!("{}{} {}self", amp, *lt, MutableSpace(mtbl)));
858 args_plain.push_str(&format!("&{} {}self", *lt, MutableSpace(mtbl)));
860 clean::SelfBorrowed(None, mtbl) => {
861 args.push_str(&format!("{}{}self", amp, MutableSpace(mtbl)));
862 args_plain.push_str(&format!("&{}self", MutableSpace(mtbl)));
864 clean::SelfExplicit(ref typ) => {
866 args.push_str(&format!("self: {:#}", *typ));
868 args.push_str(&format!("self: {}", *typ));
870 args_plain.push_str(&format!("self: {:#}", *typ));
875 args.push_str(" <br>");
876 args_plain.push_str(" ");
878 if !input.name.is_empty() {
879 args.push_str(&format!("{}: ", input.name));
880 args_plain.push_str(&format!("{}: ", input.name));
884 args.push_str(&format!("{:#}", input.type_));
886 args.push_str(&format!("{}", input.type_));
888 args_plain.push_str(&format!("{:#}", input.type_));
890 if i + 1 < decl.inputs.values.len() {
892 args_plain.push(',');
897 args.push_str(",<br> ...");
898 args_plain.push_str(", ...");
901 let arrow_plain = format!("{:#}", decl.output);
902 let arrow = if f.alternate() {
903 format!("{:#}", decl.output)
905 format!("{}", decl.output)
908 let pad = repeat(" ").take(name_len).collect::<String>();
909 let plain = format!("{pad}({args}){arrow}",
912 arrow = arrow_plain);
914 let output = if plain.len() > 80 {
915 let full_pad = format!("<br>{}", repeat(" ").take(indent + 4).collect::<String>());
916 let close_pad = format!("<br>{}", repeat(" ").take(indent).collect::<String>());
917 format!("({args}{close}){arrow}",
918 args = args.replace("<br>", &full_pad),
922 format!("({args}){arrow}", args = args.replace("<br>", ""), arrow = arrow)
926 write!(f, "{}", output.replace("<br>", "\n"))
928 write!(f, "{}", output)
933 impl<'a> fmt::Display for VisSpace<'a> {
934 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
936 Some(clean::Public) => write!(f, "pub "),
937 Some(clean::Inherited) | None => Ok(())
942 impl fmt::Display for UnsafetySpace {
943 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
945 hir::Unsafety::Unsafe => write!(f, "unsafe "),
946 hir::Unsafety::Normal => Ok(())
951 impl fmt::Display for ConstnessSpace {
952 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
954 hir::Constness::Const => write!(f, "const "),
955 hir::Constness::NotConst => Ok(())
960 impl fmt::Display for clean::Import {
961 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
963 clean::Import::Simple(ref name, ref src) => {
964 if *name == src.path.last_name() {
965 write!(f, "use {};", *src)
967 write!(f, "use {} as {};", *src, *name)
970 clean::Import::Glob(ref src) => {
971 if src.path.segments.is_empty() {
974 write!(f, "use {}::*;", *src)
981 impl fmt::Display for clean::ImportSource {
982 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
984 Some(did) => resolved_path(f, did, &self.path, true, false),
986 for (i, seg) in self.path.segments.iter().enumerate() {
990 write!(f, "{}", seg.name)?;
998 impl fmt::Display for clean::TypeBinding {
999 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1001 write!(f, "{} = {:#}", self.name, self.ty)
1003 write!(f, "{} = {}", self.name, self.ty)
1008 impl fmt::Display for MutableSpace {
1009 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1011 MutableSpace(clean::Immutable) => Ok(()),
1012 MutableSpace(clean::Mutable) => write!(f, "mut "),
1017 impl fmt::Display for RawMutableSpace {
1018 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1020 RawMutableSpace(clean::Immutable) => write!(f, "const "),
1021 RawMutableSpace(clean::Mutable) => write!(f, "mut "),
1026 impl fmt::Display for AbiSpace {
1027 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1028 let quot = if f.alternate() { "\"" } else { """ };
1030 Abi::Rust => Ok(()),
1031 abi => write!(f, "extern {0}{1}{0} ", quot, abi.name()),