2014-04-09 16:49:31 +09:00
|
|
|
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
2013-09-18 22:18:38 -07:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-10-03 10:24:40 -07:00
|
|
|
//! HTML formatting module
|
|
|
|
//!
|
2014-01-30 00:46:37 +11:00
|
|
|
//! This module contains a large number of `fmt::Show` implementations for
|
2013-10-03 10:24:40 -07:00
|
|
|
//! various types in `rustdoc::clean`. These implementations all currently
|
|
|
|
//! assume that HTML output is desired, although it may be possible to redesign
|
|
|
|
//! them in the future to instead emit any format desired.
|
|
|
|
|
2013-09-18 22:18:38 -07:00
|
|
|
use std::fmt;
|
2014-05-22 16:57:53 -07:00
|
|
|
use std::string::String;
|
2013-09-18 22:18:38 -07:00
|
|
|
|
|
|
|
use syntax::ast;
|
2013-09-24 13:55:22 -07:00
|
|
|
use syntax::ast_util;
|
2013-09-18 22:18:38 -07:00
|
|
|
|
|
|
|
use clean;
|
2014-07-04 00:51:46 -07:00
|
|
|
use stability_summary::ModuleSummary;
|
2014-04-09 16:49:31 +09:00
|
|
|
use html::item_type::ItemType;
|
2013-10-02 15:39:32 -07:00
|
|
|
use html::render;
|
2014-11-14 14:20:57 -08:00
|
|
|
use html::render::{cache, CURRENT_LOCATION_KEY};
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2013-10-03 10:24:40 -07:00
|
|
|
/// Helper to render an optional visibility with a space after it (if the
|
|
|
|
/// visibility is preset)
|
2014-12-14 23:17:42 -05:00
|
|
|
#[deriving(Copy)]
|
2014-03-31 19:01:01 -07:00
|
|
|
pub struct VisSpace(pub Option<ast::Visibility>);
|
2014-04-06 18:04:40 -07:00
|
|
|
/// Similarly to VisSpace, this structure is used to render a function style with a
|
2013-10-03 10:24:40 -07:00
|
|
|
/// space after it.
|
2014-12-14 23:17:42 -05:00
|
|
|
#[deriving(Copy)]
|
2014-12-09 10:36:46 -05:00
|
|
|
pub struct UnsafetySpace(pub ast::Unsafety);
|
2013-10-03 10:24:40 -07:00
|
|
|
/// Wrapper struct for properly emitting a method declaration.
|
2014-03-31 19:01:01 -07:00
|
|
|
pub struct Method<'a>(pub &'a clean::SelfTy, pub &'a clean::FnDecl);
|
2014-06-05 17:20:59 -07:00
|
|
|
/// Similar to VisSpace, but used for mutability
|
2014-12-14 23:17:42 -05:00
|
|
|
#[deriving(Copy)]
|
2014-06-05 17:20:59 -07:00
|
|
|
pub struct MutableSpace(pub clean::Mutability);
|
2014-07-11 11:35:02 +02:00
|
|
|
/// Similar to VisSpace, but used for mutability
|
2014-12-14 23:17:42 -05:00
|
|
|
#[deriving(Copy)]
|
2014-07-11 11:35:02 +02:00
|
|
|
pub struct RawMutableSpace(pub clean::Mutability);
|
2014-06-26 11:37:39 -07:00
|
|
|
/// Wrapper struct for properly emitting the stability level.
|
|
|
|
pub struct Stability<'a>(pub &'a Option<clean::Stability>);
|
|
|
|
/// Wrapper struct for emitting the stability level concisely.
|
|
|
|
pub struct ConciseStability<'a>(pub &'a Option<clean::Stability>);
|
2014-09-25 02:01:42 -07:00
|
|
|
/// Wrapper struct for emitting a where clause from Generics.
|
|
|
|
pub struct WhereClause<'a>(pub &'a clean::Generics);
|
|
|
|
/// Wrapper struct for emitting type parameter bounds.
|
2014-11-20 11:22:09 -08:00
|
|
|
pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]);
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2013-11-01 18:06:31 -07:00
|
|
|
impl VisSpace {
|
2014-01-09 15:05:33 +02:00
|
|
|
pub fn get(&self) -> Option<ast::Visibility> {
|
2013-11-01 18:06:31 -07:00
|
|
|
let VisSpace(v) = *self; v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-09 10:36:46 -05:00
|
|
|
impl UnsafetySpace {
|
|
|
|
pub fn get(&self) -> ast::Unsafety {
|
|
|
|
let UnsafetySpace(v) = *self; v
|
2013-11-01 18:06:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 02:01:42 -07:00
|
|
|
impl<'a> fmt::Show for TyParamBounds<'a> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let &TyParamBounds(bounds) = self;
|
|
|
|
for (i, bound) in bounds.iter().enumerate() {
|
|
|
|
if i > 0 {
|
|
|
|
try!(f.write(" + ".as_bytes()));
|
|
|
|
}
|
|
|
|
try!(write!(f, "{}", *bound));
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 00:46:37 +11:00
|
|
|
impl fmt::Show for clean::Generics {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
if self.lifetimes.len() == 0 && self.type_params.len() == 0 { return Ok(()) }
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(f.write("<".as_bytes()));
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2014-02-05 23:55:13 +11:00
|
|
|
for (i, life) in self.lifetimes.iter().enumerate() {
|
2014-01-30 11:30:21 -08:00
|
|
|
if i > 0 {
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(f.write(", ".as_bytes()));
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(write!(f, "{}", *life));
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
|
2014-02-05 23:55:13 +11:00
|
|
|
if self.type_params.len() > 0 {
|
|
|
|
if self.lifetimes.len() > 0 {
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(f.write(", ".as_bytes()));
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2014-02-05 23:55:13 +11:00
|
|
|
for (i, tp) in self.type_params.iter().enumerate() {
|
2014-01-30 11:30:21 -08:00
|
|
|
if i > 0 {
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(f.write(", ".as_bytes()))
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2014-11-24 10:14:46 -08:00
|
|
|
if let Some(ref unbound) = tp.default_unbound {
|
|
|
|
try!(write!(f, "{}? ", unbound));
|
|
|
|
};
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(f.write(tp.name.as_bytes()));
|
2013-09-18 22:18:38 -07:00
|
|
|
|
|
|
|
if tp.bounds.len() > 0 {
|
2014-09-25 02:01:42 -07:00
|
|
|
try!(write!(f, ": {}", TyParamBounds(tp.bounds.as_slice())));
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-06-21 05:03:33 -07:00
|
|
|
|
|
|
|
match tp.default {
|
|
|
|
Some(ref ty) => { try!(write!(f, " = {}", ty)); },
|
|
|
|
None => {}
|
|
|
|
};
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(f.write(">".as_bytes()));
|
2014-01-30 11:30:21 -08:00
|
|
|
Ok(())
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 02:01:42 -07:00
|
|
|
impl<'a> fmt::Show for WhereClause<'a> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let &WhereClause(gens) = self;
|
|
|
|
if gens.where_predicates.len() == 0 {
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
try!(f.write(" where ".as_bytes()));
|
|
|
|
for (i, pred) in gens.where_predicates.iter().enumerate() {
|
|
|
|
if i > 0 {
|
|
|
|
try!(f.write(", ".as_bytes()));
|
|
|
|
}
|
|
|
|
let bounds = pred.bounds.as_slice();
|
|
|
|
try!(write!(f, "{}: {}", pred.name, TyParamBounds(bounds)));
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 00:46:37 +11:00
|
|
|
impl fmt::Show for clean::Lifetime {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(f.write(self.get_ref().as_bytes()));
|
2014-01-30 11:30:21 -08:00
|
|
|
Ok(())
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 00:46:37 +11:00
|
|
|
impl fmt::Show for clean::TyParamBound {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
2014-10-05 07:35:04 -07:00
|
|
|
clean::RegionBound(ref lt) => {
|
|
|
|
write!(f, "{}", *lt)
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
clean::TraitBound(ref ty) => {
|
2014-05-10 14:05:06 -07:00
|
|
|
write!(f, "{}", *ty)
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 00:46:37 +11:00
|
|
|
impl fmt::Show for clean::Path {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
if self.global {
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(f.write("::".as_bytes()))
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2014-05-10 14:05:06 -07:00
|
|
|
|
2014-02-05 23:55:13 +11:00
|
|
|
for (i, seg) in self.segments.iter().enumerate() {
|
2014-01-30 11:30:21 -08:00
|
|
|
if i > 0 {
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(f.write("::".as_bytes()))
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(f.write(seg.name.as_bytes()));
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2013-10-29 06:03:32 -04:00
|
|
|
if seg.lifetimes.len() > 0 || seg.types.len() > 0 {
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(f.write("<".as_bytes()));
|
2013-10-29 06:03:32 -04:00
|
|
|
let mut comma = false;
|
|
|
|
for lifetime in seg.lifetimes.iter() {
|
2014-01-30 11:30:21 -08:00
|
|
|
if comma {
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(f.write(", ".as_bytes()));
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2013-10-29 06:03:32 -04:00
|
|
|
comma = true;
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(write!(f, "{}", *lifetime));
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2013-10-29 06:03:32 -04:00
|
|
|
for ty in seg.types.iter() {
|
2014-01-30 11:30:21 -08:00
|
|
|
if comma {
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(f.write(", ".as_bytes()));
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2013-10-29 06:03:32 -04:00
|
|
|
comma = true;
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(write!(f, "{}", *ty));
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(f.write(">".as_bytes()));
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
2014-01-30 11:30:21 -08:00
|
|
|
Ok(())
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-03 10:24:40 -07:00
|
|
|
/// Used when rendering a `ResolvedPath` structure. This invokes the `path`
|
|
|
|
/// rendering function with the necessary arguments for linking to a local path.
|
2014-05-10 14:05:06 -07:00
|
|
|
fn resolved_path(w: &mut fmt::Formatter, did: ast::DefId, p: &clean::Path,
|
2014-01-30 11:30:21 -08:00
|
|
|
print_all: bool) -> fmt::Result {
|
2013-10-02 15:39:32 -07:00
|
|
|
path(w, p, print_all,
|
2014-05-09 13:52:17 -07:00
|
|
|
|cache, loc| {
|
2014-05-26 21:51:59 -07:00
|
|
|
if ast_util::is_local(did) || cache.inlined.contains(&did) {
|
2014-05-25 03:17:19 -07:00
|
|
|
Some(("../".repeat(loc.len())).to_string())
|
2014-05-09 13:52:17 -07:00
|
|
|
} else {
|
2014-08-02 18:48:44 +12:00
|
|
|
match cache.extern_locations[did.krate] {
|
2014-05-25 03:17:19 -07:00
|
|
|
render::Remote(ref s) => Some(s.to_string()),
|
2014-05-12 13:44:59 -07:00
|
|
|
render::Local => {
|
2014-05-25 03:17:19 -07:00
|
|
|
Some(("../".repeat(loc.len())).to_string())
|
2014-05-12 13:44:59 -07:00
|
|
|
}
|
2014-05-09 13:52:17 -07:00
|
|
|
render::Unknown => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2013-10-02 15:39:32 -07:00
|
|
|
|cache| {
|
2014-11-06 12:25:16 -05:00
|
|
|
match cache.paths.get(&did) {
|
2013-10-02 15:39:32 -07:00
|
|
|
None => None,
|
|
|
|
Some(&(ref fqp, shortty)) => Some((fqp.clone(), shortty))
|
|
|
|
}
|
2014-01-30 11:30:21 -08:00
|
|
|
})
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
|
|
|
|
2014-12-09 15:22:19 -05:00
|
|
|
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)>,
|
2014-01-30 11:30:21 -08:00
|
|
|
{
|
2013-09-18 22:18:38 -07:00
|
|
|
// The generics will get written to both the title and link
|
2014-05-22 16:57:53 -07:00
|
|
|
let mut generics = String::new();
|
2013-12-23 15:08:23 +01:00
|
|
|
let last = path.segments.last().unwrap();
|
2013-10-29 06:03:32 -04:00
|
|
|
if last.lifetimes.len() > 0 || last.types.len() > 0 {
|
2014-06-27 12:30:25 -07:00
|
|
|
let mut counter = 0u;
|
2013-09-18 22:18:38 -07:00
|
|
|
generics.push_str("<");
|
2013-10-29 06:03:32 -04:00
|
|
|
for lifetime in last.lifetimes.iter() {
|
|
|
|
if counter > 0 { generics.push_str(", "); }
|
|
|
|
counter += 1;
|
2014-05-16 10:45:16 -07:00
|
|
|
generics.push_str(format!("{}", *lifetime).as_slice());
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2013-10-29 06:03:32 -04:00
|
|
|
for ty in last.types.iter() {
|
|
|
|
if counter > 0 { generics.push_str(", "); }
|
|
|
|
counter += 1;
|
2014-05-16 10:45:16 -07:00
|
|
|
generics.push_str(format!("{}", *ty).as_slice());
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
generics.push_str(">");
|
|
|
|
}
|
|
|
|
|
2014-11-14 14:20:57 -08:00
|
|
|
let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
|
|
|
|
let cache = cache();
|
|
|
|
let abs_root = root(&*cache, loc.as_slice());
|
2014-07-15 11:37:25 +12:00
|
|
|
let rel_root = match path.segments[0].name.as_slice() {
|
2014-05-25 03:10:11 -07:00
|
|
|
"self" => Some("./".to_string()),
|
2014-04-28 20:36:08 -07:00
|
|
|
_ => None,
|
|
|
|
};
|
2013-09-24 13:56:52 -07:00
|
|
|
|
2014-04-28 20:36:08 -07:00
|
|
|
if print_all {
|
|
|
|
let amt = path.segments.len() - 1;
|
|
|
|
match rel_root {
|
|
|
|
Some(root) => {
|
2014-05-22 16:57:53 -07:00
|
|
|
let mut root = String::from_str(root.as_slice());
|
2014-09-24 23:41:09 +12:00
|
|
|
for seg in path.segments[..amt].iter() {
|
2014-11-27 14:19:27 -05:00
|
|
|
if "super" == seg.name ||
|
|
|
|
"self" == seg.name {
|
2014-04-28 20:36:08 -07:00
|
|
|
try!(write!(w, "{}::", seg.name));
|
|
|
|
} else {
|
2014-05-12 13:44:59 -07:00
|
|
|
root.push_str(seg.name.as_slice());
|
2014-04-28 20:36:08 -07:00
|
|
|
root.push_str("/");
|
|
|
|
try!(write!(w, "<a class='mod'
|
|
|
|
href='{}index.html'>{}</a>::",
|
|
|
|
root.as_slice(),
|
|
|
|
seg.name));
|
2013-12-05 18:19:06 -08:00
|
|
|
}
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
2013-12-05 18:19:06 -08:00
|
|
|
}
|
2014-04-28 20:36:08 -07:00
|
|
|
None => {
|
2014-09-24 23:41:09 +12:00
|
|
|
for seg in path.segments[..amt].iter() {
|
2014-04-28 20:36:08 -07:00
|
|
|
try!(write!(w, "{}::", seg.name));
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
2014-04-28 20:36:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-05 18:19:06 -08:00
|
|
|
|
2014-11-14 14:20:57 -08:00
|
|
|
match info(&*cache) {
|
2014-04-28 20:36:08 -07:00
|
|
|
// This is a documented path, link to it!
|
|
|
|
Some((ref fqp, shortty)) if abs_root.is_some() => {
|
2014-05-22 16:57:53 -07:00
|
|
|
let mut url = String::from_str(abs_root.unwrap().as_slice());
|
2014-09-24 23:41:09 +12:00
|
|
|
let to_link = fqp[..fqp.len() - 1];
|
2014-04-28 20:36:08 -07:00
|
|
|
for component in to_link.iter() {
|
2014-05-12 13:44:59 -07:00
|
|
|
url.push_str(component.as_slice());
|
2014-04-28 20:36:08 -07:00
|
|
|
url.push_str("/");
|
|
|
|
}
|
|
|
|
match shortty {
|
2014-12-03 23:57:45 +09:00
|
|
|
ItemType::Module => {
|
2014-05-12 13:44:59 -07:00
|
|
|
url.push_str(fqp.last().unwrap().as_slice());
|
2014-04-28 20:36:08 -07:00
|
|
|
url.push_str("/index.html");
|
|
|
|
}
|
2013-12-05 18:19:06 -08:00
|
|
|
_ => {
|
2014-04-28 20:36:08 -07:00
|
|
|
url.push_str(shortty.to_static_str());
|
|
|
|
url.push_str(".");
|
2014-05-12 13:44:59 -07:00
|
|
|
url.push_str(fqp.last().unwrap().as_slice());
|
2014-04-28 20:36:08 -07:00
|
|
|
url.push_str(".html");
|
2013-12-05 18:19:06 -08:00
|
|
|
}
|
|
|
|
}
|
2014-04-28 20:36:08 -07:00
|
|
|
|
|
|
|
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(())
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
|
2014-05-28 19:53:37 -07:00
|
|
|
fn primitive_link(f: &mut fmt::Formatter,
|
2014-09-11 17:07:49 +12:00
|
|
|
prim: clean::PrimitiveType,
|
2014-05-28 19:53:37 -07:00
|
|
|
name: &str) -> fmt::Result {
|
2014-11-14 14:20:57 -08:00
|
|
|
let m = cache();
|
2014-05-28 19:53:37 -07:00
|
|
|
let mut needs_termination = false;
|
2014-11-06 12:25:16 -05:00
|
|
|
match m.primitive_locations.get(&prim) {
|
2014-05-28 19:53:37 -07:00
|
|
|
Some(&ast::LOCAL_CRATE) => {
|
2014-11-14 14:20:57 -08:00
|
|
|
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
|
|
|
|
let len = if len == 0 {0} else {len - 1};
|
2014-05-28 19:53:37 -07:00
|
|
|
try!(write!(f, "<a href='{}primitive.{}.html'>",
|
|
|
|
"../".repeat(len),
|
|
|
|
prim.to_url_str()));
|
|
|
|
needs_termination = true;
|
|
|
|
}
|
|
|
|
Some(&cnum) => {
|
2014-08-02 18:48:44 +12:00
|
|
|
let path = &m.paths[ast::DefId {
|
2014-05-29 09:58:09 -07:00
|
|
|
krate: cnum,
|
|
|
|
node: ast::CRATE_NODE_ID,
|
2014-08-02 18:48:44 +12:00
|
|
|
}];
|
|
|
|
let loc = match m.extern_locations[cnum] {
|
2014-05-28 19:53:37 -07:00
|
|
|
render::Remote(ref s) => Some(s.to_string()),
|
|
|
|
render::Local => {
|
2014-11-14 14:20:57 -08:00
|
|
|
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
|
|
|
|
Some("../".repeat(len))
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
|
|
|
render::Unknown => None,
|
|
|
|
};
|
|
|
|
match loc {
|
2014-05-29 09:58:09 -07:00
|
|
|
Some(root) => {
|
|
|
|
try!(write!(f, "<a href='{}{}/primitive.{}.html'>",
|
|
|
|
root,
|
2014-12-09 12:58:15 -05:00
|
|
|
path.0.head().unwrap(),
|
2014-05-29 09:58:09 -07:00
|
|
|
prim.to_url_str()));
|
2014-05-28 19:53:37 -07:00
|
|
|
needs_termination = true;
|
|
|
|
}
|
|
|
|
None => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => {}
|
|
|
|
}
|
|
|
|
try!(write!(f, "{}", name));
|
|
|
|
if needs_termination {
|
|
|
|
try!(write!(f, "</a>"));
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2013-10-03 10:24:40 -07:00
|
|
|
/// Helper to render type parameters
|
2014-05-10 14:05:06 -07:00
|
|
|
fn tybounds(w: &mut fmt::Formatter,
|
2014-03-05 15:28:08 -08:00
|
|
|
typarams: &Option<Vec<clean::TyParamBound> >) -> fmt::Result {
|
2013-10-02 15:39:32 -07:00
|
|
|
match *typarams {
|
|
|
|
Some(ref params) => {
|
2014-06-16 22:14:21 -07:00
|
|
|
for param in params.iter() {
|
|
|
|
try!(write!(w, " + "));
|
2014-02-19 10:07:49 -08:00
|
|
|
try!(write!(w, "{}", *param));
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
2014-01-30 11:30:21 -08:00
|
|
|
Ok(())
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
2014-01-30 11:30:21 -08:00
|
|
|
None => Ok(())
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 00:46:37 +11:00
|
|
|
impl fmt::Show for clean::Type {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
2014-05-03 02:08:58 -07:00
|
|
|
clean::TyParamBinder(id) => {
|
2014-11-14 14:20:57 -08:00
|
|
|
f.write(cache().typarams[ast_util::local_def(id)].as_bytes())
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-05-03 02:08:58 -07:00
|
|
|
clean::Generic(did) => {
|
2014-11-14 14:20:57 -08:00
|
|
|
f.write(cache().typarams[did].as_bytes())
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
clean::ResolvedPath{ did, ref typarams, ref path } => {
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(resolved_path(f, did, path, false));
|
2014-05-11 11:14:14 -07:00
|
|
|
tybounds(f, typarams)
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-11-26 10:11:27 -05:00
|
|
|
clean::PolyTraitRef(ref bounds) => {
|
|
|
|
for (i, bound) in bounds.iter().enumerate() {
|
|
|
|
if i != 0 {
|
|
|
|
try!(write!(f, " + "));
|
|
|
|
}
|
|
|
|
try!(write!(f, "{}", *bound));
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
clean::Infer => write!(f, "_"),
|
2014-05-10 14:05:06 -07:00
|
|
|
clean::Self(..) => f.write("Self".as_bytes()),
|
2014-06-21 03:39:03 -07:00
|
|
|
clean::Primitive(prim) => primitive_link(f, prim, prim.to_string()),
|
2014-08-27 21:46:52 -04:00
|
|
|
clean::Closure(ref decl) => {
|
2014-05-28 09:24:28 -07:00
|
|
|
write!(f, "{style}{lifetimes}|{args}|{bounds}{arrow}",
|
2014-12-09 10:36:46 -05:00
|
|
|
style = UnsafetySpace(decl.unsafety),
|
2014-04-11 12:45:51 -07:00
|
|
|
lifetimes = if decl.lifetimes.len() == 0 {
|
2014-05-25 03:17:19 -07:00
|
|
|
"".to_string()
|
2014-04-11 12:45:51 -07:00
|
|
|
} else {
|
|
|
|
format!("<{:#}>", decl.lifetimes)
|
|
|
|
},
|
|
|
|
args = decl.decl.inputs,
|
2014-11-09 16:14:15 +01:00
|
|
|
arrow = decl.decl.output,
|
2014-04-11 12:45:51 -07:00
|
|
|
bounds = {
|
2014-05-22 16:57:53 -07:00
|
|
|
let mut ret = String::new();
|
2014-04-11 12:45:51 -07:00
|
|
|
for bound in decl.bounds.iter() {
|
|
|
|
match *bound {
|
2014-11-04 16:25:15 -05:00
|
|
|
clean::RegionBound(..) => {}
|
2014-04-11 12:45:51 -07:00
|
|
|
clean::TraitBound(ref t) => {
|
|
|
|
if ret.len() == 0 {
|
|
|
|
ret.push_str(": ");
|
|
|
|
} else {
|
|
|
|
ret.push_str(" + ");
|
|
|
|
}
|
2014-05-16 10:45:16 -07:00
|
|
|
ret.push_str(format!("{}",
|
|
|
|
*t).as_slice());
|
2014-04-11 12:45:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-28 20:45:44 -07:00
|
|
|
ret
|
2014-04-11 12:45:51 -07:00
|
|
|
})
|
2014-04-09 15:34:35 +03:00
|
|
|
}
|
|
|
|
clean::Proc(ref decl) => {
|
2014-05-28 09:24:28 -07:00
|
|
|
write!(f, "{style}{lifetimes}proc({args}){bounds}{arrow}",
|
2014-12-09 10:36:46 -05:00
|
|
|
style = UnsafetySpace(decl.unsafety),
|
2014-04-11 12:45:51 -07:00
|
|
|
lifetimes = if decl.lifetimes.len() == 0 {
|
2014-05-25 03:17:19 -07:00
|
|
|
"".to_string()
|
2014-04-11 12:45:51 -07:00
|
|
|
} else {
|
2014-05-27 20:44:58 -07:00
|
|
|
format!("<{:#}>", decl.lifetimes)
|
2014-04-11 12:45:51 -07:00
|
|
|
},
|
|
|
|
args = decl.decl.inputs,
|
|
|
|
bounds = if decl.bounds.len() == 0 {
|
2014-05-25 03:17:19 -07:00
|
|
|
"".to_string()
|
2014-04-11 12:45:51 -07:00
|
|
|
} else {
|
2014-11-06 09:32:37 -08:00
|
|
|
let m = decl.bounds
|
2014-05-12 13:44:59 -07:00
|
|
|
.iter()
|
2014-06-21 03:39:03 -07:00
|
|
|
.map(|s| s.to_string());
|
2014-05-27 20:44:58 -07:00
|
|
|
format!(
|
2014-05-12 13:44:59 -07:00
|
|
|
": {}",
|
2014-05-22 16:57:53 -07:00
|
|
|
m.collect::<Vec<String>>().connect(" + "))
|
2014-04-11 12:45:51 -07:00
|
|
|
},
|
2014-11-09 16:14:15 +01:00
|
|
|
arrow = decl.decl.output)
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
clean::BareFunction(ref decl) => {
|
2014-05-10 14:05:06 -07:00
|
|
|
write!(f, "{}{}fn{}{}",
|
2014-12-09 10:36:46 -05:00
|
|
|
UnsafetySpace(decl.unsafety),
|
2014-05-06 18:43:56 -07:00
|
|
|
match decl.abi.as_slice() {
|
2014-05-25 03:17:19 -07:00
|
|
|
"" => " extern ".to_string(),
|
|
|
|
"\"Rust\"" => "".to_string(),
|
2014-05-27 20:44:58 -07:00
|
|
|
s => format!(" extern {} ", s)
|
2013-09-18 22:18:38 -07:00
|
|
|
},
|
|
|
|
decl.generics,
|
2014-01-30 11:30:21 -08:00
|
|
|
decl.decl)
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
clean::Tuple(ref typs) => {
|
2014-05-29 13:50:47 -07:00
|
|
|
primitive_link(f, clean::PrimitiveTuple,
|
2014-07-11 21:51:29 +02:00
|
|
|
match typs.as_slice() {
|
|
|
|
[ref one] => format!("({},)", one),
|
|
|
|
many => format!("({:#})", many)
|
|
|
|
}.as_slice())
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-05-28 19:53:37 -07:00
|
|
|
clean::Vector(ref t) => {
|
|
|
|
primitive_link(f, clean::Slice, format!("[{}]", **t).as_slice())
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
clean::FixedVector(ref t, ref s) => {
|
2014-05-28 19:53:37 -07:00
|
|
|
primitive_link(f, clean::Slice,
|
|
|
|
format!("[{}, ..{}]", **t, *s).as_slice())
|
2014-05-10 14:05:06 -07:00
|
|
|
}
|
|
|
|
clean::Bottom => f.write("!".as_bytes()),
|
2013-09-18 22:18:38 -07:00
|
|
|
clean::RawPointer(m, ref t) => {
|
2014-07-11 11:35:02 +02:00
|
|
|
write!(f, "*{}{}", RawMutableSpace(m), **t)
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => {
|
2014-05-16 10:45:16 -07:00
|
|
|
let lt = match *l {
|
|
|
|
Some(ref l) => format!("{} ", *l),
|
2014-05-25 03:17:19 -07:00
|
|
|
_ => "".to_string(),
|
2014-05-16 10:45:16 -07:00
|
|
|
};
|
2014-09-28 00:15:31 +08:00
|
|
|
let m = MutableSpace(mutability);
|
|
|
|
match **ty {
|
|
|
|
clean::Vector(ref bt) => { // BorrowedRef{ ... Vector(T) } is &[T]
|
|
|
|
match **bt {
|
|
|
|
clean::Generic(_) =>
|
|
|
|
primitive_link(f, clean::Slice,
|
|
|
|
format!("&{}{}[{}]", lt, m, **bt).as_slice()),
|
|
|
|
_ => {
|
|
|
|
try!(primitive_link(f, clean::Slice,
|
|
|
|
format!("&{}{}[", lt, m).as_slice()));
|
|
|
|
try!(write!(f, "{}", **bt));
|
|
|
|
primitive_link(f, clean::Slice, "]")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
write!(f, "&{}{}{}", lt, m, **ty)
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-11-20 21:45:05 -08:00
|
|
|
clean::QPath { ref name, ref self_type, ref trait_ } => {
|
|
|
|
write!(f, "<{} as {}>::{}", self_type, trait_, name)
|
|
|
|
}
|
2014-10-01 01:42:04 +03:00
|
|
|
clean::Unique(..) => {
|
2014-10-09 15:17:22 -04:00
|
|
|
panic!("should have been cleaned")
|
2014-07-25 09:31:20 -07:00
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-13 06:41:34 +11:00
|
|
|
impl fmt::Show for clean::Arguments {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
for (i, input) in self.values.iter().enumerate() {
|
2014-05-10 14:05:06 -07:00
|
|
|
if i > 0 { try!(write!(f, ", ")); }
|
2014-02-13 06:41:34 +11:00
|
|
|
if input.name.len() > 0 {
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(write!(f, "{}: ", input.name));
|
2014-02-13 06:41:34 +11:00
|
|
|
}
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(write!(f, "{}", input.type_));
|
2014-02-13 06:41:34 +11:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-09 16:14:15 +01:00
|
|
|
impl fmt::Show for clean::FunctionRetTy {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
|
|
|
clean::Return(clean::Tuple(ref tys)) if tys.is_empty() => Ok(()),
|
|
|
|
clean::Return(ref ty) => write!(f, " -> {}", ty),
|
|
|
|
clean::NoReturn => write!(f, " -> !")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 00:46:37 +11:00
|
|
|
impl fmt::Show for clean::FnDecl {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2014-11-09 16:14:15 +01:00
|
|
|
write!(f, "({args}){arrow}", args = self.inputs, arrow = self.output)
|
2013-11-28 02:23:12 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 00:46:37 +11:00
|
|
|
impl<'a> fmt::Show for Method<'a> {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let Method(selfty, d) = *self;
|
2014-05-22 16:57:53 -07:00
|
|
|
let mut args = String::new();
|
2013-09-18 22:18:38 -07:00
|
|
|
match *selfty {
|
|
|
|
clean::SelfStatic => {},
|
|
|
|
clean::SelfValue => args.push_str("self"),
|
2014-06-05 17:20:59 -07:00
|
|
|
clean::SelfBorrowed(Some(ref lt), mtbl) => {
|
|
|
|
args.push_str(format!("&{} {}self", *lt,
|
|
|
|
MutableSpace(mtbl)).as_slice());
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-06-05 17:20:59 -07:00
|
|
|
clean::SelfBorrowed(None, mtbl) => {
|
|
|
|
args.push_str(format!("&{}self",
|
|
|
|
MutableSpace(mtbl)).as_slice());
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-05-06 16:37:32 -07:00
|
|
|
clean::SelfExplicit(ref typ) => {
|
|
|
|
args.push_str(format!("self: {}", *typ).as_slice());
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-02-13 06:41:34 +11:00
|
|
|
for (i, input) in d.inputs.values.iter().enumerate() {
|
2013-09-18 22:18:38 -07:00
|
|
|
if i > 0 || args.len() > 0 { args.push_str(", "); }
|
|
|
|
if input.name.len() > 0 {
|
2014-05-16 10:45:16 -07:00
|
|
|
args.push_str(format!("{}: ", input.name).as_slice());
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-05-16 10:45:16 -07:00
|
|
|
args.push_str(format!("{}", input.type_).as_slice());
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-11-09 16:14:15 +01:00
|
|
|
write!(f, "({args}){arrow}", args = args, arrow = d.output)
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 00:46:37 +11:00
|
|
|
impl fmt::Show for VisSpace {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self.get() {
|
2014-05-10 14:05:06 -07:00
|
|
|
Some(ast::Public) => write!(f, "pub "),
|
2014-01-30 11:30:21 -08:00
|
|
|
Some(ast::Inherited) | None => Ok(())
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-23 20:38:17 -07:00
|
|
|
|
2014-12-09 10:36:46 -05:00
|
|
|
impl fmt::Show for UnsafetySpace {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self.get() {
|
2014-12-09 10:36:46 -05:00
|
|
|
ast::Unsafety::Unsafe => write!(f, "unsafe "),
|
|
|
|
ast::Unsafety::Normal => Ok(())
|
2013-09-23 20:38:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-24 13:56:52 -07:00
|
|
|
|
2014-01-30 00:46:37 +11:00
|
|
|
impl fmt::Show for clean::ViewPath {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
2013-09-24 13:56:52 -07:00
|
|
|
clean::SimpleImport(ref name, ref src) => {
|
2013-12-23 15:08:23 +01:00
|
|
|
if *name == src.path.segments.last().unwrap().name {
|
2014-05-10 14:05:06 -07:00
|
|
|
write!(f, "use {};", *src)
|
2013-09-24 13:56:52 -07:00
|
|
|
} else {
|
2014-08-18 08:29:44 -07:00
|
|
|
write!(f, "use {} as {};", *src, *name)
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
clean::GlobImport(ref src) => {
|
2014-05-10 14:05:06 -07:00
|
|
|
write!(f, "use {}::*;", *src)
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
|
|
|
clean::ImportList(ref src, ref names) => {
|
2014-05-28 09:24:28 -07:00
|
|
|
try!(write!(f, "use {}::{{", *src));
|
2013-09-24 13:56:52 -07:00
|
|
|
for (i, n) in names.iter().enumerate() {
|
2014-01-30 11:30:21 -08:00
|
|
|
if i > 0 {
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(write!(f, ", "));
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(write!(f, "{}", *n));
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
2014-05-28 09:24:28 -07:00
|
|
|
write!(f, "}};")
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 00:46:37 +11:00
|
|
|
impl fmt::Show for clean::ImportSource {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self.did {
|
2014-05-10 14:05:06 -07:00
|
|
|
Some(did) => resolved_path(f, did, &self.path, true),
|
2013-09-24 13:56:52 -07:00
|
|
|
_ => {
|
2014-02-05 23:55:13 +11:00
|
|
|
for (i, seg) in self.path.segments.iter().enumerate() {
|
2014-01-30 11:30:21 -08:00
|
|
|
if i > 0 {
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(write!(f, "::"))
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2014-05-10 14:05:06 -07:00
|
|
|
try!(write!(f, "{}", seg.name));
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
2014-01-30 11:30:21 -08:00
|
|
|
Ok(())
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 00:46:37 +11:00
|
|
|
impl fmt::Show for clean::ViewListIdent {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self.source {
|
2014-05-09 13:52:17 -07:00
|
|
|
Some(did) => {
|
2013-09-24 13:56:52 -07:00
|
|
|
let path = clean::Path {
|
|
|
|
global: false,
|
2014-03-05 15:28:08 -08:00
|
|
|
segments: vec!(clean::PathSegment {
|
2014-02-05 23:55:13 +11:00
|
|
|
name: self.name.clone(),
|
2014-03-05 15:28:08 -08:00
|
|
|
lifetimes: Vec::new(),
|
|
|
|
types: Vec::new(),
|
|
|
|
})
|
2013-09-24 13:56:52 -07:00
|
|
|
};
|
2014-05-10 14:05:06 -07:00
|
|
|
resolved_path(f, did, &path, false)
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
2014-05-10 14:05:06 -07:00
|
|
|
_ => write!(f, "{}", self.name),
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-05 17:20:59 -07:00
|
|
|
|
|
|
|
impl fmt::Show for MutableSpace {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
|
|
|
MutableSpace(clean::Immutable) => Ok(()),
|
|
|
|
MutableSpace(clean::Mutable) => write!(f, "mut "),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-26 11:37:39 -07:00
|
|
|
|
2014-07-11 11:35:02 +02:00
|
|
|
impl fmt::Show for RawMutableSpace {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
|
|
|
RawMutableSpace(clean::Immutable) => write!(f, "const "),
|
|
|
|
RawMutableSpace(clean::Mutable) => write!(f, "mut "),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 11:37:39 -07:00
|
|
|
impl<'a> fmt::Show for Stability<'a> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let Stability(stab) = *self;
|
|
|
|
match *stab {
|
|
|
|
Some(ref stability) => {
|
|
|
|
write!(f, "<a class='stability {lvl}' title='{reason}'>{lvl}</a>",
|
2014-06-21 03:39:03 -07:00
|
|
|
lvl = stability.level.to_string(),
|
2014-06-26 11:37:39 -07:00
|
|
|
reason = stability.text)
|
|
|
|
}
|
|
|
|
None => Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> fmt::Show for ConciseStability<'a> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let ConciseStability(stab) = *self;
|
|
|
|
match *stab {
|
|
|
|
Some(ref stability) => {
|
|
|
|
write!(f, "<a class='stability {lvl}' title='{lvl}{colon}{reason}'></a>",
|
2014-06-21 03:39:03 -07:00
|
|
|
lvl = stability.level.to_string(),
|
2014-06-26 11:37:39 -07:00
|
|
|
colon = if stability.text.len() > 0 { ": " } else { "" },
|
|
|
|
reason = stability.text)
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
write!(f, "<a class='stability Unmarked' title='No stability level'></a>")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-04 00:51:46 -07:00
|
|
|
|
|
|
|
impl fmt::Show for ModuleSummary {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
fn fmt_inner<'a>(f: &mut fmt::Formatter,
|
|
|
|
context: &mut Vec<&'a str>,
|
|
|
|
m: &'a ModuleSummary)
|
|
|
|
-> fmt::Result {
|
|
|
|
let cnt = m.counts;
|
|
|
|
let tot = cnt.total();
|
|
|
|
if tot == 0 { return Ok(()) }
|
|
|
|
|
|
|
|
context.push(m.name.as_slice());
|
|
|
|
let path = context.connect("::");
|
|
|
|
|
|
|
|
try!(write!(f, "<tr>"));
|
2014-10-14 23:05:01 -07:00
|
|
|
try!(write!(f, "<td><a href='{}'>{}</a></td>", {
|
|
|
|
let mut url = context.slice_from(1).to_vec();
|
|
|
|
url.push("index.html");
|
|
|
|
url.connect("/")
|
|
|
|
},
|
2014-07-04 00:51:46 -07:00
|
|
|
path));
|
2014-07-27 23:03:46 -07:00
|
|
|
try!(write!(f, "<td class='summary-column'>"));
|
2014-07-04 00:51:46 -07:00
|
|
|
try!(write!(f, "<span class='summary Stable' \
|
2014-07-27 23:03:46 -07:00
|
|
|
style='width: {:.4}%; display: inline-block'> </span>",
|
|
|
|
(100 * cnt.stable) as f64/tot as f64));
|
2014-07-04 00:51:46 -07:00
|
|
|
try!(write!(f, "<span class='summary Unstable' \
|
2014-07-27 23:03:46 -07:00
|
|
|
style='width: {:.4}%; display: inline-block'> </span>",
|
|
|
|
(100 * cnt.unstable) as f64/tot as f64));
|
2014-07-04 00:51:46 -07:00
|
|
|
try!(write!(f, "<span class='summary Experimental' \
|
2014-07-27 23:03:46 -07:00
|
|
|
style='width: {:.4}%; display: inline-block'> </span>",
|
|
|
|
(100 * cnt.experimental) as f64/tot as f64));
|
2014-07-04 00:51:46 -07:00
|
|
|
try!(write!(f, "<span class='summary Deprecated' \
|
2014-07-27 23:03:46 -07:00
|
|
|
style='width: {:.4}%; display: inline-block'> </span>",
|
|
|
|
(100 * cnt.deprecated) as f64/tot as f64));
|
2014-07-04 00:51:46 -07:00
|
|
|
try!(write!(f, "<span class='summary Unmarked' \
|
2014-07-27 23:03:46 -07:00
|
|
|
style='width: {:.4}%; display: inline-block'> </span>",
|
|
|
|
(100 * cnt.unmarked) as f64/tot as f64));
|
2014-07-04 00:51:46 -07:00
|
|
|
try!(write!(f, "</td></tr>"));
|
|
|
|
|
|
|
|
for submodule in m.submodules.iter() {
|
|
|
|
try!(fmt_inner(f, context, submodule));
|
|
|
|
}
|
|
|
|
context.pop();
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut context = Vec::new();
|
|
|
|
|
2014-07-27 23:03:46 -07:00
|
|
|
let tot = self.counts.total();
|
|
|
|
let (stable, unstable, experimental, deprecated, unmarked) = if tot == 0 {
|
|
|
|
(0, 0, 0, 0, 0)
|
|
|
|
} else {
|
|
|
|
((100 * self.counts.stable)/tot,
|
|
|
|
(100 * self.counts.unstable)/tot,
|
|
|
|
(100 * self.counts.experimental)/tot,
|
|
|
|
(100 * self.counts.deprecated)/tot,
|
|
|
|
(100 * self.counts.unmarked)/tot)
|
|
|
|
};
|
|
|
|
|
2014-07-04 00:51:46 -07:00
|
|
|
try!(write!(f,
|
2014-07-27 23:03:46 -07:00
|
|
|
r"<h1 class='fqn'>Stability dashboard: crate <a class='mod' href='index.html'>{name}</a></h1>
|
2014-07-04 00:51:46 -07:00
|
|
|
This dashboard summarizes the stability levels for all of the public modules of
|
2014-07-27 23:03:46 -07:00
|
|
|
the crate, according to the total number of items at each level in the module and
|
|
|
|
its children (percentages total for {name}):
|
2014-07-04 00:51:46 -07:00
|
|
|
<blockquote>
|
2014-07-27 23:03:46 -07:00
|
|
|
<a class='stability Stable'></a> stable ({}%),<br/>
|
|
|
|
<a class='stability Unstable'></a> unstable ({}%),<br/>
|
|
|
|
<a class='stability Experimental'></a> experimental ({}%),<br/>
|
|
|
|
<a class='stability Deprecated'></a> deprecated ({}%),<br/>
|
|
|
|
<a class='stability Unmarked'></a> unmarked ({}%)
|
2014-07-04 00:51:46 -07:00
|
|
|
</blockquote>
|
|
|
|
The counts do not include methods or trait
|
|
|
|
implementations that are visible only through a re-exported type.",
|
2014-07-27 23:03:46 -07:00
|
|
|
stable, unstable, experimental, deprecated, unmarked,
|
|
|
|
name=self.name));
|
2014-11-14 09:18:10 -08:00
|
|
|
try!(write!(f, "<table>"));
|
2014-07-04 00:51:46 -07:00
|
|
|
try!(fmt_inner(f, &mut context, self));
|
|
|
|
write!(f, "</table>")
|
|
|
|
}
|
|
|
|
}
|