2015-07-02 03:52:40 +00:00
|
|
|
// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT
|
2013-09-19 05:18:38 +00: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 17:24:40 +00:00
|
|
|
//! Rustdoc's HTML Rendering module
|
|
|
|
//!
|
|
|
|
//! This modules contains the bulk of the logic necessary for rendering a
|
|
|
|
//! rustdoc `clean::Crate` instance to a set of static HTML pages. This
|
|
|
|
//! rendering process is largely driven by the `format!` syntax extension to
|
|
|
|
//! perform all I/O into files and streams.
|
|
|
|
//!
|
|
|
|
//! The rendering process is largely driven by the `Context` and `Cache`
|
|
|
|
//! structures. The cache is pre-populated by crawling the crate in question,
|
2015-05-08 15:12:29 +00:00
|
|
|
//! and then it is shared among the various rendering threads. The cache is meant
|
2013-10-03 17:24:40 +00:00
|
|
|
//! to be a fairly large structure not implementing `Clone` (because it's shared
|
2015-05-08 15:12:29 +00:00
|
|
|
//! among threads). The context, however, should be a lightweight structure. This
|
|
|
|
//! is cloned per-thread and contains information about what is currently being
|
2013-10-03 17:24:40 +00:00
|
|
|
//! rendered.
|
|
|
|
//!
|
|
|
|
//! In order to speed up rendering (mostly because of markdown rendering), the
|
|
|
|
//! rendering process has been parallelized. This parallelization is only
|
|
|
|
//! exposed through the `crate` method on the context, and then also from the
|
|
|
|
//! fact that the shared cache is stored in TLS (and must be accessed as such).
|
|
|
|
//!
|
|
|
|
//! In addition to rendering the crate itself, this module is also responsible
|
|
|
|
//! for creating the corresponding search index and source file renderings.
|
2015-05-08 15:12:29 +00:00
|
|
|
//! These threads are not parallelized (they haven't been a bottleneck yet), and
|
2013-10-03 17:24:40 +00:00
|
|
|
//! both occur before the crate is rendered.
|
2014-11-06 08:05:53 +00:00
|
|
|
pub use self::ExternalLocation::*;
|
2013-10-03 17:24:40 +00:00
|
|
|
|
2015-07-08 15:33:13 +00:00
|
|
|
use std::ascii::AsciiExt;
|
2014-11-14 22:20:57 +00:00
|
|
|
use std::cell::RefCell;
|
2014-12-26 08:55:16 +00:00
|
|
|
use std::cmp::Ordering;
|
2015-04-16 10:14:45 +00:00
|
|
|
use std::collections::{BTreeMap, HashMap, HashSet};
|
2014-11-14 22:20:57 +00:00
|
|
|
use std::default::Default;
|
2015-09-26 21:59:32 +00:00
|
|
|
use std::error;
|
|
|
|
use std::fmt::{self, Display, Formatter};
|
2015-02-27 05:00:43 +00:00
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::io::prelude::*;
|
|
|
|
use std::io::{self, BufWriter, BufReader};
|
2014-12-11 03:46:38 +00:00
|
|
|
use std::iter::repeat;
|
2015-04-06 22:10:55 +00:00
|
|
|
use std::mem;
|
2016-02-23 06:52:43 +00:00
|
|
|
use std::path::{PathBuf, Path, Component};
|
2014-04-02 23:54:22 +00:00
|
|
|
use std::str;
|
2014-06-07 18:13:26 +00:00
|
|
|
use std::sync::Arc;
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2014-06-28 10:35:25 +00:00
|
|
|
use externalfiles::ExternalHtml;
|
|
|
|
|
2016-02-16 18:48:28 +00:00
|
|
|
use serialize::json::{ToJson, Json, as_json};
|
2015-10-13 03:01:31 +00:00
|
|
|
use syntax::{abi, ast};
|
2016-02-01 18:05:37 +00:00
|
|
|
use syntax::feature_gate::UnstableFeatures;
|
2015-11-24 23:23:22 +00:00
|
|
|
use rustc::middle::cstore::LOCAL_CRATE;
|
2015-09-17 18:29:59 +00:00
|
|
|
use rustc::middle::def_id::{CRATE_DEF_INDEX, DefId};
|
2015-11-19 11:16:35 +00:00
|
|
|
use rustc::middle::privacy::AccessLevels;
|
2015-10-13 03:01:31 +00:00
|
|
|
use rustc::middle::stability;
|
2016-02-01 18:05:37 +00:00
|
|
|
use rustc::session::config::get_unstable_features_setting;
|
2015-09-14 09:58:20 +00:00
|
|
|
use rustc_front::hir;
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2016-02-28 09:12:41 +00:00
|
|
|
use clean::{self, SelfTy, Attributes};
|
2013-09-19 05:18:38 +00:00
|
|
|
use doctree;
|
|
|
|
use fold::DocFolder;
|
2015-04-13 18:55:00 +00:00
|
|
|
use html::escape::Escape;
|
2015-02-25 20:05:07 +00:00
|
|
|
use html::format::{ConstnessSpace};
|
2015-04-13 18:55:00 +00:00
|
|
|
use html::format::{TyParamBounds, WhereClause, href, AbiSpace};
|
|
|
|
use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace};
|
2014-12-03 14:57:45 +00:00
|
|
|
use html::item_type::ItemType;
|
2015-04-26 19:03:38 +00:00
|
|
|
use html::markdown::{self, Markdown};
|
|
|
|
use html::{highlight, layout};
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2014-12-23 01:58:38 +00:00
|
|
|
/// A pair of name and its optional document.
|
2015-03-05 07:35:43 +00:00
|
|
|
pub type NameDoc = (String, Option<String>);
|
2014-12-23 01:58:38 +00:00
|
|
|
|
2013-10-03 17:24:40 +00:00
|
|
|
/// Major driving force in all rustdoc rendering. This contains information
|
|
|
|
/// about where in the tree-like hierarchy rendering is occurring and controls
|
|
|
|
/// how the current page is being rendered.
|
|
|
|
///
|
|
|
|
/// It is intended that this context is a lightweight object which can be fairly
|
|
|
|
/// easily cloned because it is cloned per work-job (about once per item in the
|
|
|
|
/// rustdoc tree).
|
2015-01-04 03:54:18 +00:00
|
|
|
#[derive(Clone)]
|
2013-09-19 05:18:38 +00:00
|
|
|
pub struct Context {
|
2013-10-03 17:24:40 +00:00
|
|
|
/// Current hierarchy of components leading down to what's currently being
|
|
|
|
/// rendered
|
2014-05-29 20:50:47 +00:00
|
|
|
pub current: Vec<String>,
|
2013-10-03 17:24:40 +00:00
|
|
|
/// String representation of how to get back to the root path of the 'doc/'
|
|
|
|
/// folder in terms of a relative URL.
|
2014-05-22 23:57:53 +00:00
|
|
|
pub root_path: String,
|
2014-12-01 11:46:51 +00:00
|
|
|
/// The path to the crate root source minus the file name.
|
|
|
|
/// Used for simplifying paths to the highlighted source code files.
|
2015-02-27 05:00:43 +00:00
|
|
|
pub src_root: PathBuf,
|
2013-10-03 17:24:40 +00:00
|
|
|
/// The current destination folder of where HTML artifacts should be placed.
|
|
|
|
/// This changes as the context descends into the module hierarchy.
|
2015-02-27 05:00:43 +00:00
|
|
|
pub dst: PathBuf,
|
2013-10-03 17:24:40 +00:00
|
|
|
/// This describes the layout of each page, and is not modified after
|
2014-06-28 10:35:25 +00:00
|
|
|
/// creation of the context (contains info like the favicon and added html).
|
2014-03-28 17:27:24 +00:00
|
|
|
pub layout: layout::Layout,
|
2013-10-03 17:24:40 +00:00
|
|
|
/// This flag indicates whether [src] links should be generated or not. If
|
|
|
|
/// the source files are present in the html rendering, then this will be
|
|
|
|
/// `true`.
|
2014-03-28 17:27:24 +00:00
|
|
|
pub include_sources: bool,
|
2016-02-27 06:35:05 +00:00
|
|
|
/// The local file sources we've emitted and their respective url-paths.
|
|
|
|
pub local_sources: HashMap<PathBuf, String>,
|
2014-05-29 20:50:47 +00:00
|
|
|
/// A flag, which when turned off, will render pages which redirect to the
|
|
|
|
/// real location of an item. This is used to allow external links to
|
|
|
|
/// publicly reused items to redirect to the right location.
|
|
|
|
pub render_redirect_pages: bool,
|
2014-11-10 00:09:17 +00:00
|
|
|
/// All the passes that were run on this crate.
|
|
|
|
pub passes: HashSet<String>,
|
2015-08-16 13:53:18 +00:00
|
|
|
/// The base-URL of the issue tracker for when an item has been tagged with
|
|
|
|
/// an issue number.
|
|
|
|
pub issue_tracker_base_url: Option<String>,
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2013-10-03 17:24:40 +00:00
|
|
|
/// Indicates where an external crate can be found.
|
2013-10-02 22:39:32 +00:00
|
|
|
pub enum ExternalLocation {
|
2013-10-03 17:24:40 +00:00
|
|
|
/// Remote URL root of the external crate
|
2014-05-22 23:57:53 +00:00
|
|
|
Remote(String),
|
2013-10-03 17:24:40 +00:00
|
|
|
/// This external crate can be found in the local doc/ folder
|
|
|
|
Local,
|
|
|
|
/// The external crate could not be found.
|
|
|
|
Unknown,
|
2013-10-02 22:39:32 +00:00
|
|
|
}
|
|
|
|
|
2014-05-28 00:52:40 +00:00
|
|
|
/// Metadata about an implementor of a trait.
|
|
|
|
pub struct Implementor {
|
2015-08-16 10:32:28 +00:00
|
|
|
pub def_id: DefId,
|
2014-11-10 23:33:21 +00:00
|
|
|
pub stability: Option<clean::Stability>,
|
2015-07-18 06:02:57 +00:00
|
|
|
pub impl_: clean::Impl,
|
2014-06-26 18:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Metadata about implementations for a type.
|
2015-01-04 03:54:18 +00:00
|
|
|
#[derive(Clone)]
|
2014-06-26 18:37:39 +00:00
|
|
|
pub struct Impl {
|
2014-11-10 23:33:21 +00:00
|
|
|
pub impl_: clean::Impl,
|
|
|
|
pub dox: Option<String>,
|
|
|
|
pub stability: Option<clean::Stability>,
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 00:56:35 +00:00
|
|
|
impl Impl {
|
2015-08-16 10:32:28 +00:00
|
|
|
fn trait_did(&self) -> Option<DefId> {
|
2015-04-07 00:56:35 +00:00
|
|
|
self.impl_.trait_.as_ref().and_then(|tr| {
|
|
|
|
if let clean::ResolvedPath { did, .. } = *tr {Some(did)} else {None}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-26 21:59:32 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Error {
|
|
|
|
file: PathBuf,
|
|
|
|
error: io::Error,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl error::Error for Error {
|
|
|
|
fn description(&self) -> &str {
|
|
|
|
self.error.description()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for Error {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
|
|
|
write!(f, "\"{}\": {}", self.file.display(), self.error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Error {
|
|
|
|
pub fn new(e: io::Error, file: &Path) -> Error {
|
|
|
|
Error {
|
|
|
|
file: file.to_path_buf(),
|
|
|
|
error: e,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! try_err {
|
|
|
|
($e:expr, $file:expr) => ({
|
|
|
|
match $e {
|
|
|
|
Ok(e) => e,
|
|
|
|
Err(e) => return Err(Error::new(e, $file)),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2013-10-03 17:24:40 +00:00
|
|
|
/// This cache is used to store information about the `clean::Crate` being
|
|
|
|
/// rendered in order to provide more useful documentation. This contains
|
|
|
|
/// information like all implementors of a trait, all traits a type implements,
|
|
|
|
/// documentation for all known traits, etc.
|
|
|
|
///
|
|
|
|
/// This structure purposefully does not implement `Clone` because it's intended
|
|
|
|
/// to be a fairly large and expensive structure to clone. Instead this adheres
|
2014-03-22 13:42:32 +00:00
|
|
|
/// to `Send` so it may be stored in a `Arc` instance and shared among the various
|
2015-05-08 15:12:29 +00:00
|
|
|
/// rendering threads.
|
2015-01-04 03:54:18 +00:00
|
|
|
#[derive(Default)]
|
2013-10-05 21:44:37 +00:00
|
|
|
pub struct Cache {
|
2013-10-03 17:24:40 +00:00
|
|
|
/// Mapping of typaram ids to the name of the type parameter. This is used
|
|
|
|
/// when pretty-printing a type (so pretty printing doesn't have to
|
|
|
|
/// painfully maintain a context like this)
|
2015-08-16 10:32:28 +00:00
|
|
|
pub typarams: HashMap<DefId, String>,
|
2013-10-03 17:24:40 +00:00
|
|
|
|
|
|
|
/// Maps a type id to all known implementations for that type. This is only
|
|
|
|
/// recognized for intra-crate `ResolvedPath` types, and is used to print
|
|
|
|
/// out extra documentation on the page of an enum/struct.
|
|
|
|
///
|
|
|
|
/// The values of the map are a list of implementations and documentation
|
|
|
|
/// found on that implementation.
|
2015-08-16 10:32:28 +00:00
|
|
|
pub impls: HashMap<DefId, Vec<Impl>>,
|
2013-10-03 17:24:40 +00:00
|
|
|
|
|
|
|
/// Maintains a mapping of local crate node ids to the fully qualified name
|
|
|
|
/// and "short type description" of that node. This is used when generating
|
|
|
|
/// URLs when a type is being linked to. External paths are not located in
|
|
|
|
/// this map because the `External` type itself has all the information
|
|
|
|
/// necessary.
|
2015-08-16 10:32:28 +00:00
|
|
|
pub paths: HashMap<DefId, (Vec<String>, ItemType)>,
|
2013-10-03 17:24:40 +00:00
|
|
|
|
2014-05-24 03:17:27 +00:00
|
|
|
/// Similar to `paths`, but only holds external paths. This is only used for
|
|
|
|
/// generating explicit hyperlinks to other crates.
|
2015-08-16 10:32:28 +00:00
|
|
|
pub external_paths: HashMap<DefId, Vec<String>>,
|
2014-05-24 03:17:27 +00:00
|
|
|
|
2013-10-03 17:24:40 +00:00
|
|
|
/// This map contains information about all known traits of this crate.
|
|
|
|
/// Implementations of a crate should inherit the documentation of the
|
2013-10-21 18:33:04 +00:00
|
|
|
/// parent trait if no extra documentation is specified, and default methods
|
|
|
|
/// should show up in documentation about trait implementations.
|
2015-08-16 10:32:28 +00:00
|
|
|
pub traits: HashMap<DefId, clean::Trait>,
|
2013-10-03 17:24:40 +00:00
|
|
|
|
|
|
|
/// When rendering traits, it's often useful to be able to list all
|
|
|
|
/// implementors of the trait, and this mapping is exactly, that: a mapping
|
|
|
|
/// of trait ids to the list of known implementors of the trait
|
2015-08-16 10:32:28 +00:00
|
|
|
pub implementors: HashMap<DefId, Vec<Implementor>>,
|
2013-10-03 17:24:40 +00:00
|
|
|
|
|
|
|
/// Cache of where external crate documentation can be found.
|
2015-04-13 22:25:40 +00:00
|
|
|
pub extern_locations: HashMap<ast::CrateNum, (String, ExternalLocation)>,
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2014-05-29 02:53:37 +00:00
|
|
|
/// Cache of where documentation for primitives can be found.
|
2014-09-11 05:07:49 +00:00
|
|
|
pub primitive_locations: HashMap<clean::PrimitiveType, ast::CrateNum>,
|
2014-05-29 02:53:37 +00:00
|
|
|
|
2014-05-27 04:51:59 +00:00
|
|
|
/// Set of definitions which have been inlined from external crates.
|
2015-08-16 10:32:28 +00:00
|
|
|
pub inlined: HashSet<DefId>,
|
2014-05-27 04:51:59 +00:00
|
|
|
|
2013-10-03 17:24:40 +00:00
|
|
|
// Private fields only used when initially crawling a crate to build a cache
|
|
|
|
|
2014-05-23 05:00:18 +00:00
|
|
|
stack: Vec<String>,
|
2015-08-16 10:32:28 +00:00
|
|
|
parent_stack: Vec<DefId>,
|
2016-02-23 08:52:44 +00:00
|
|
|
parent_is_trait_impl: bool,
|
2014-05-23 05:00:18 +00:00
|
|
|
search_index: Vec<IndexItem>,
|
2014-03-28 17:27:24 +00:00
|
|
|
privmod: bool,
|
2014-11-10 00:09:17 +00:00
|
|
|
remove_priv: bool,
|
2015-11-19 11:16:35 +00:00
|
|
|
access_levels: AccessLevels<DefId>,
|
2015-08-16 10:32:28 +00:00
|
|
|
deref_trait_did: Option<DefId>,
|
2014-03-07 09:26:06 +00:00
|
|
|
|
|
|
|
// In rare case where a structure is defined in one module but implemented
|
|
|
|
// in another, if the implementing module is parsed before defining module,
|
|
|
|
// then the fully qualified name of the structure isn't presented in `paths`
|
|
|
|
// yet when its implementation methods are being indexed. Caches such methods
|
|
|
|
// and their parent id here and indexes them at the end of crate parsing.
|
2015-09-02 20:11:32 +00:00
|
|
|
orphan_methods: Vec<(DefId, clean::Item)>,
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2013-10-03 17:24:40 +00:00
|
|
|
/// Helper struct to render all source code to HTML pages
|
2013-12-10 07:16:18 +00:00
|
|
|
struct SourceCollector<'a> {
|
|
|
|
cx: &'a mut Context,
|
2013-10-03 17:24:40 +00:00
|
|
|
|
|
|
|
/// Root destination to place all HTML output into
|
2015-02-27 05:00:43 +00:00
|
|
|
dst: PathBuf,
|
2013-09-27 22:12:23 +00:00
|
|
|
}
|
|
|
|
|
2013-10-03 17:24:40 +00:00
|
|
|
/// Wrapper struct to render the source code of a file. This will do things like
|
|
|
|
/// adding line numbers to the left-hand side.
|
2013-12-10 07:16:18 +00:00
|
|
|
struct Source<'a>(&'a str);
|
2013-10-03 17:24:40 +00:00
|
|
|
|
|
|
|
// Helper structs for rendering items/sidebars and carrying along contextual
|
|
|
|
// information
|
|
|
|
|
2015-03-30 13:40:52 +00:00
|
|
|
#[derive(Copy, Clone)]
|
librustc: Make `Copy` opt-in.
This change makes the compiler no longer infer whether types (structures
and enumerations) implement the `Copy` trait (and thus are implicitly
copyable). Rather, you must implement `Copy` yourself via `impl Copy for
MyType {}`.
A new warning has been added, `missing_copy_implementations`, to warn
you if a non-generic public type has been added that could have
implemented `Copy` but didn't.
For convenience, you may *temporarily* opt out of this behavior by using
`#![feature(opt_out_copy)]`. Note though that this feature gate will never be
accepted and will be removed by the time that 1.0 is released, so you should
transition your code away from using it.
This breaks code like:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
Change this code to:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
impl Copy for Point2D {}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
This is the backwards-incompatible part of #13231.
Part of RFC #3.
[breaking-change]
2014-12-06 01:01:33 +00:00
|
|
|
struct Item<'a> {
|
|
|
|
cx: &'a Context,
|
|
|
|
item: &'a clean::Item,
|
|
|
|
}
|
|
|
|
|
2013-12-10 07:16:18 +00:00
|
|
|
struct Sidebar<'a> { cx: &'a Context, item: &'a clean::Item, }
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2013-10-03 17:24:40 +00:00
|
|
|
/// Struct representing one entry in the JS search index. These are all emitted
|
|
|
|
/// by hand to a large JS file at the end of cache-creation.
|
2013-09-19 05:18:38 +00:00
|
|
|
struct IndexItem {
|
2014-04-09 07:49:31 +00:00
|
|
|
ty: ItemType,
|
2014-05-22 23:57:53 +00:00
|
|
|
name: String,
|
|
|
|
path: String,
|
|
|
|
desc: String,
|
2015-08-16 10:32:28 +00:00
|
|
|
parent: Option<DefId>,
|
2016-02-16 18:48:28 +00:00
|
|
|
parent_idx: Option<usize>,
|
2015-02-25 23:03:06 +00:00
|
|
|
search_type: Option<IndexItemFunctionType>,
|
|
|
|
}
|
|
|
|
|
2016-02-16 18:48:28 +00:00
|
|
|
impl ToJson for IndexItem {
|
|
|
|
fn to_json(&self) -> Json {
|
|
|
|
assert_eq!(self.parent.is_some(), self.parent_idx.is_some());
|
|
|
|
|
|
|
|
let mut data = Vec::with_capacity(6);
|
|
|
|
data.push((self.ty as usize).to_json());
|
|
|
|
data.push(self.name.to_json());
|
|
|
|
data.push(self.path.to_json());
|
|
|
|
data.push(self.desc.to_json());
|
|
|
|
data.push(self.parent_idx.to_json());
|
|
|
|
data.push(self.search_type.to_json());
|
|
|
|
|
|
|
|
Json::Array(data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-25 23:03:06 +00:00
|
|
|
/// A type used for the search index.
|
|
|
|
struct Type {
|
|
|
|
name: Option<String>,
|
|
|
|
}
|
|
|
|
|
2016-02-16 18:48:28 +00:00
|
|
|
impl ToJson for Type {
|
|
|
|
fn to_json(&self) -> Json {
|
2015-02-25 23:03:06 +00:00
|
|
|
match self.name {
|
2016-02-16 18:48:28 +00:00
|
|
|
Some(ref name) => {
|
|
|
|
let mut data = BTreeMap::new();
|
|
|
|
data.insert("name".to_owned(), name.to_json());
|
|
|
|
Json::Object(data)
|
|
|
|
},
|
|
|
|
None => Json::Null
|
2015-02-25 23:03:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Full type of functions/methods in the search index.
|
|
|
|
struct IndexItemFunctionType {
|
|
|
|
inputs: Vec<Type>,
|
|
|
|
output: Option<Type>
|
|
|
|
}
|
|
|
|
|
2016-02-16 18:48:28 +00:00
|
|
|
impl ToJson for IndexItemFunctionType {
|
|
|
|
fn to_json(&self) -> Json {
|
2015-02-25 23:03:06 +00:00
|
|
|
// If we couldn't figure out a type, just write `null`.
|
2016-02-16 18:48:28 +00:00
|
|
|
if self.inputs.iter().chain(self.output.iter()).any(|ref i| i.name.is_none()) {
|
|
|
|
Json::Null
|
|
|
|
} else {
|
|
|
|
let mut data = BTreeMap::new();
|
|
|
|
data.insert("inputs".to_owned(), self.inputs.to_json());
|
|
|
|
data.insert("output".to_owned(), self.output.to_json());
|
|
|
|
Json::Object(data)
|
2015-02-25 23:03:06 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2013-10-03 17:24:40 +00:00
|
|
|
// TLS keys used to carry information around during rendering.
|
2013-09-27 22:12:23 +00:00
|
|
|
|
2014-11-14 17:18:10 +00:00
|
|
|
thread_local!(static CACHE_KEY: RefCell<Arc<Cache>> = Default::default());
|
2014-11-14 22:20:57 +00:00
|
|
|
thread_local!(pub static CURRENT_LOCATION_KEY: RefCell<Vec<String>> =
|
2014-11-14 17:18:10 +00:00
|
|
|
RefCell::new(Vec::new()));
|
2015-12-02 23:06:26 +00:00
|
|
|
thread_local!(static USED_ID_MAP: RefCell<HashMap<String, usize>> =
|
2015-12-03 01:19:23 +00:00
|
|
|
RefCell::new(init_ids()));
|
|
|
|
|
|
|
|
fn init_ids() -> HashMap<String, usize> {
|
|
|
|
[
|
|
|
|
"main",
|
|
|
|
"search",
|
|
|
|
"help",
|
|
|
|
"TOC",
|
|
|
|
"render-detail",
|
|
|
|
"associated-types",
|
|
|
|
"associated-const",
|
|
|
|
"required-methods",
|
|
|
|
"provided-methods",
|
|
|
|
"implementors",
|
|
|
|
"implementors-list",
|
|
|
|
"methods",
|
|
|
|
"deref-methods",
|
|
|
|
"implementations",
|
|
|
|
"derived_implementations"
|
2016-02-28 15:38:51 +00:00
|
|
|
].into_iter().map(|id| (String::from(*id), 1)).collect()
|
2015-12-03 01:19:23 +00:00
|
|
|
}
|
2015-12-02 23:06:26 +00:00
|
|
|
|
|
|
|
/// This method resets the local table of used ID attributes. This is typically
|
|
|
|
/// used at the beginning of rendering an entire HTML page to reset from the
|
|
|
|
/// previous state (if any).
|
|
|
|
pub fn reset_ids() {
|
2015-12-03 01:19:23 +00:00
|
|
|
USED_ID_MAP.with(|s| *s.borrow_mut() = init_ids());
|
2015-12-02 23:06:26 +00:00
|
|
|
}
|
|
|
|
|
2015-12-03 23:48:59 +00:00
|
|
|
pub fn derive_id(candidate: String) -> String {
|
2015-12-02 23:06:26 +00:00
|
|
|
USED_ID_MAP.with(|map| {
|
2015-12-03 23:48:59 +00:00
|
|
|
let id = match map.borrow_mut().get_mut(&candidate) {
|
|
|
|
None => candidate,
|
2015-12-02 23:06:26 +00:00
|
|
|
Some(a) => {
|
|
|
|
let id = format!("{}-{}", candidate, *a);
|
|
|
|
*a += 1;
|
2015-12-03 23:48:59 +00:00
|
|
|
id
|
2015-12-02 23:06:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-03 23:48:59 +00:00
|
|
|
map.borrow_mut().insert(id.clone(), 1);
|
|
|
|
id
|
2015-12-02 23:06:26 +00:00
|
|
|
})
|
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
|
|
/// Generates the documentation for `crate` into the directory `dst`
|
2014-11-10 00:09:17 +00:00
|
|
|
pub fn run(mut krate: clean::Crate,
|
|
|
|
external_html: &ExternalHtml,
|
2015-02-27 05:00:43 +00:00
|
|
|
dst: PathBuf,
|
2015-09-26 21:59:32 +00:00
|
|
|
passes: HashSet<String>) -> Result<(), Error> {
|
2015-02-27 05:00:43 +00:00
|
|
|
let src_root = match krate.src.parent() {
|
|
|
|
Some(p) => p.to_path_buf(),
|
2015-03-18 16:14:54 +00:00
|
|
|
None => PathBuf::new(),
|
2015-02-27 05:00:43 +00:00
|
|
|
};
|
2013-09-19 05:18:38 +00:00
|
|
|
let mut cx = Context {
|
|
|
|
dst: dst,
|
2015-02-27 05:00:43 +00:00
|
|
|
src_root: src_root,
|
2014-11-10 00:09:17 +00:00
|
|
|
passes: passes,
|
2014-03-05 23:28:08 +00:00
|
|
|
current: Vec::new(),
|
2014-05-22 23:57:53 +00:00
|
|
|
root_path: String::new(),
|
2013-09-19 05:18:38 +00:00
|
|
|
layout: layout::Layout {
|
2014-05-25 10:17:19 +00:00
|
|
|
logo: "".to_string(),
|
|
|
|
favicon: "".to_string(),
|
2014-06-28 10:35:25 +00:00
|
|
|
external_html: external_html.clone(),
|
2014-02-05 21:15:24 +00:00
|
|
|
krate: krate.name.clone(),
|
2014-06-06 16:12:18 +00:00
|
|
|
playground_url: "".to_string(),
|
2013-09-19 05:18:38 +00:00
|
|
|
},
|
2013-09-27 22:12:23 +00:00
|
|
|
include_sources: true,
|
2016-02-27 06:35:05 +00:00
|
|
|
local_sources: HashMap::new(),
|
2014-05-29 20:50:47 +00:00
|
|
|
render_redirect_pages: false,
|
2015-08-17 18:24:28 +00:00
|
|
|
issue_tracker_base_url: None,
|
2013-09-19 05:18:38 +00:00
|
|
|
};
|
2014-06-28 10:35:25 +00:00
|
|
|
|
2015-09-26 21:59:32 +00:00
|
|
|
try_err!(mkdir(&cx.dst), &cx.dst);
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2014-05-28 00:12:48 +00:00
|
|
|
// Crawl the crate attributes looking for attributes which control how we're
|
|
|
|
// going to emit HTML
|
2016-02-28 09:12:41 +00:00
|
|
|
if let Some(attrs) = krate.module.as_ref().map(|m| m.attrs.list_def("doc")) {
|
2016-02-28 11:11:13 +00:00
|
|
|
for attr in attrs {
|
|
|
|
match *attr {
|
|
|
|
clean::NameValue(ref x, ref s)
|
|
|
|
if "html_favicon_url" == *x => {
|
|
|
|
cx.layout.favicon = s.to_string();
|
|
|
|
}
|
|
|
|
clean::NameValue(ref x, ref s)
|
|
|
|
if "html_logo_url" == *x => {
|
|
|
|
cx.layout.logo = s.to_string();
|
|
|
|
}
|
|
|
|
clean::NameValue(ref x, ref s)
|
|
|
|
if "html_playground_url" == *x => {
|
|
|
|
cx.layout.playground_url = s.to_string();
|
|
|
|
markdown::PLAYGROUND_KRATE.with(|slot| {
|
|
|
|
if slot.borrow().is_none() {
|
|
|
|
let name = krate.name.clone();
|
|
|
|
*slot.borrow_mut() = Some(Some(name));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
clean::NameValue(ref x, ref s)
|
|
|
|
if "issue_tracker_base_url" == *x => {
|
|
|
|
cx.issue_tracker_base_url = Some(s.to_string());
|
|
|
|
}
|
|
|
|
clean::Word(ref x)
|
|
|
|
if "html_no_source" == *x => {
|
|
|
|
cx.include_sources = false;
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2016-02-28 11:11:13 +00:00
|
|
|
_ => {}
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Crawl the crate to build various caches used for the output
|
2014-11-14 22:20:57 +00:00
|
|
|
let analysis = ::ANALYSISKEY.with(|a| a.clone());
|
|
|
|
let analysis = analysis.borrow();
|
2015-11-19 11:16:35 +00:00
|
|
|
let access_levels = analysis.as_ref().map(|a| a.access_levels.clone());
|
|
|
|
let access_levels = access_levels.unwrap_or(Default::default());
|
2015-08-16 10:32:28 +00:00
|
|
|
let paths: HashMap<DefId, (Vec<String>, ItemType)> =
|
2014-05-24 03:17:27 +00:00
|
|
|
analysis.as_ref().map(|a| {
|
2014-08-19 00:52:38 +00:00
|
|
|
let paths = a.external_paths.borrow_mut().take().unwrap();
|
2014-12-03 14:57:45 +00:00
|
|
|
paths.into_iter().map(|(k, (v, t))| (k, (v, ItemType::from_type_kind(t)))).collect()
|
|
|
|
}).unwrap_or(HashMap::new());
|
2014-04-29 03:36:08 +00:00
|
|
|
let mut cache = Cache {
|
|
|
|
impls: HashMap::new(),
|
2014-12-09 17:58:15 +00:00
|
|
|
external_paths: paths.iter().map(|(&k, v)| (k, v.0.clone()))
|
2014-05-24 03:17:27 +00:00
|
|
|
.collect(),
|
2014-05-09 20:52:17 +00:00
|
|
|
paths: paths,
|
2014-04-29 03:36:08 +00:00
|
|
|
implementors: HashMap::new(),
|
|
|
|
stack: Vec::new(),
|
|
|
|
parent_stack: Vec::new(),
|
|
|
|
search_index: Vec::new(),
|
2016-02-23 08:52:44 +00:00
|
|
|
parent_is_trait_impl: false,
|
2014-04-29 03:36:08 +00:00
|
|
|
extern_locations: HashMap::new(),
|
2014-05-29 02:53:37 +00:00
|
|
|
primitive_locations: HashMap::new(),
|
2014-11-10 00:09:17 +00:00
|
|
|
remove_priv: cx.passes.contains("strip-private"),
|
2014-04-29 03:36:08 +00:00
|
|
|
privmod: false,
|
2015-11-19 11:16:35 +00:00
|
|
|
access_levels: access_levels,
|
2014-04-29 03:36:08 +00:00
|
|
|
orphan_methods: Vec::new(),
|
2015-04-06 22:10:55 +00:00
|
|
|
traits: mem::replace(&mut krate.external_traits, HashMap::new()),
|
2015-04-13 23:23:32 +00:00
|
|
|
deref_trait_did: analysis.as_ref().and_then(|a| a.deref_trait_did),
|
2014-05-03 09:08:58 +00:00
|
|
|
typarams: analysis.as_ref().map(|a| {
|
2014-08-19 00:52:38 +00:00
|
|
|
a.external_typarams.borrow_mut().take().unwrap()
|
2014-05-03 09:08:58 +00:00
|
|
|
}).unwrap_or(HashMap::new()),
|
2014-05-27 04:51:59 +00:00
|
|
|
inlined: analysis.as_ref().map(|a| {
|
2014-08-19 00:52:38 +00:00
|
|
|
a.inlined.borrow_mut().take().unwrap()
|
2014-05-27 04:51:59 +00:00
|
|
|
}).unwrap_or(HashSet::new()),
|
2014-04-29 03:36:08 +00:00
|
|
|
};
|
2014-04-09 06:52:31 +00:00
|
|
|
|
2014-05-29 02:53:37 +00:00
|
|
|
// Cache where all our extern crates are located
|
2015-01-31 17:20:46 +00:00
|
|
|
for &(n, ref e) in &krate.externs {
|
2015-04-13 22:25:40 +00:00
|
|
|
cache.extern_locations.insert(n, (e.name.clone(),
|
|
|
|
extern_location(e, &cx.dst)));
|
2015-09-17 18:29:59 +00:00
|
|
|
let did = DefId { krate: n, index: CRATE_DEF_INDEX };
|
2014-12-03 14:57:45 +00:00
|
|
|
cache.paths.insert(did, (vec![e.name.to_string()], ItemType::Module));
|
2014-05-28 00:12:48 +00:00
|
|
|
}
|
|
|
|
|
2014-05-29 02:53:37 +00:00
|
|
|
// Cache where all known primitives have their documentation located.
|
|
|
|
//
|
|
|
|
// Favor linking to as local extern as possible, so iterate all crates in
|
|
|
|
// reverse topological order.
|
|
|
|
for &(n, ref e) in krate.externs.iter().rev() {
|
2015-01-31 17:20:46 +00:00
|
|
|
for &prim in &e.primitives {
|
2014-05-29 02:53:37 +00:00
|
|
|
cache.primitive_locations.insert(prim, n);
|
|
|
|
}
|
|
|
|
}
|
2015-01-31 17:20:46 +00:00
|
|
|
for &prim in &krate.primitives {
|
2015-08-16 10:32:28 +00:00
|
|
|
cache.primitive_locations.insert(prim, LOCAL_CRATE);
|
2014-05-29 02:53:37 +00:00
|
|
|
}
|
|
|
|
|
2015-04-13 23:23:32 +00:00
|
|
|
cache.stack.push(krate.name.clone());
|
|
|
|
krate = cache.fold_crate(krate);
|
|
|
|
|
2014-05-29 02:53:37 +00:00
|
|
|
// Build our search index
|
2015-09-26 21:59:32 +00:00
|
|
|
let index = build_index(&krate, &mut cache);
|
2014-05-28 00:15:10 +00:00
|
|
|
|
|
|
|
// Freeze the cache now that the index has been built. Put an Arc into TLS
|
|
|
|
// for future parallelization opportunities
|
|
|
|
let cache = Arc::new(cache);
|
2014-11-14 22:20:57 +00:00
|
|
|
CACHE_KEY.with(|v| *v.borrow_mut() = cache.clone());
|
|
|
|
CURRENT_LOCATION_KEY.with(|s| s.borrow_mut().clear());
|
2014-05-28 00:15:10 +00:00
|
|
|
|
|
|
|
try!(write_shared(&cx, &krate, &*cache, index));
|
2014-05-28 00:12:48 +00:00
|
|
|
let krate = try!(render_sources(&mut cx, krate));
|
|
|
|
|
|
|
|
// And finally render the whole crate's documentation
|
2015-04-13 18:55:00 +00:00
|
|
|
cx.krate(krate)
|
2014-05-28 00:12:48 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 19:00:57 +00:00
|
|
|
/// Build the search index from the collected metadata
|
2015-09-26 21:59:32 +00:00
|
|
|
fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
|
2014-04-09 06:52:31 +00:00
|
|
|
let mut nodeid_to_pathid = HashMap::new();
|
2016-02-16 18:48:28 +00:00
|
|
|
let mut crate_items = Vec::with_capacity(cache.search_index.len());
|
|
|
|
let mut crate_paths = Vec::<Json>::new();
|
|
|
|
|
|
|
|
let Cache { ref mut search_index,
|
|
|
|
ref orphan_methods,
|
|
|
|
ref mut paths, .. } = *cache;
|
|
|
|
|
|
|
|
// Attach all orphan methods to the type's definition if the type
|
|
|
|
// has since been learned.
|
|
|
|
for &(did, ref item) in orphan_methods {
|
|
|
|
match paths.get(&did) {
|
|
|
|
Some(&(ref fqp, _)) => {
|
|
|
|
// Needed to determine `self` type.
|
|
|
|
let parent_basename = Some(fqp[fqp.len() - 1].clone());
|
|
|
|
search_index.push(IndexItem {
|
|
|
|
ty: shortty(item),
|
|
|
|
name: item.name.clone().unwrap(),
|
|
|
|
path: fqp[..fqp.len() - 1].join("::"),
|
|
|
|
desc: Escape(&shorter(item.doc_value())).to_string(),
|
|
|
|
parent: Some(did),
|
|
|
|
parent_idx: None,
|
|
|
|
search_type: get_index_search_type(&item, parent_basename),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
None => {}
|
2014-04-08 18:25:54 +00:00
|
|
|
}
|
2014-03-07 09:26:06 +00:00
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2016-02-16 18:48:28 +00:00
|
|
|
// Reduce `NodeId` in paths into smaller sequential numbers,
|
|
|
|
// and prune the paths that do not appear in the index.
|
|
|
|
let mut lastpath = String::new();
|
|
|
|
let mut lastpathid = 0usize;
|
2016-02-16 19:00:57 +00:00
|
|
|
|
2016-02-16 18:48:28 +00:00
|
|
|
for item in search_index {
|
|
|
|
item.parent_idx = item.parent.map(|nodeid| {
|
|
|
|
if nodeid_to_pathid.contains_key(&nodeid) {
|
|
|
|
*nodeid_to_pathid.get(&nodeid).unwrap()
|
|
|
|
} else {
|
|
|
|
let pathid = lastpathid;
|
|
|
|
nodeid_to_pathid.insert(nodeid, pathid);
|
|
|
|
lastpathid += 1;
|
2014-05-28 00:12:48 +00:00
|
|
|
|
2016-02-16 18:48:28 +00:00
|
|
|
let &(ref fqp, short) = paths.get(&nodeid).unwrap();
|
|
|
|
crate_paths.push(((short as usize), fqp.last().unwrap().clone()).to_json());
|
|
|
|
pathid
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Omit the parent path if it is same to that of the prior item.
|
2014-11-27 19:19:27 +00:00
|
|
|
if lastpath == item.path {
|
2016-02-16 18:48:28 +00:00
|
|
|
item.path.clear();
|
2014-05-28 00:12:48 +00:00
|
|
|
} else {
|
2016-02-16 18:48:28 +00:00
|
|
|
lastpath = item.path.clone();
|
2014-05-28 00:12:48 +00:00
|
|
|
}
|
2016-02-16 18:48:28 +00:00
|
|
|
crate_items.push(item.to_json());
|
2014-05-28 00:12:48 +00:00
|
|
|
}
|
2014-04-09 17:24:00 +00:00
|
|
|
|
2016-02-16 18:48:28 +00:00
|
|
|
let crate_doc = krate.module.as_ref().map(|module| {
|
|
|
|
Escape(&shorter(module.doc_value())).to_string()
|
|
|
|
}).unwrap_or(String::new());
|
2014-04-09 17:24:00 +00:00
|
|
|
|
2016-02-16 18:48:28 +00:00
|
|
|
let mut crate_data = BTreeMap::new();
|
|
|
|
crate_data.insert("doc".to_owned(), Json::String(crate_doc));
|
|
|
|
crate_data.insert("items".to_owned(), Json::Array(crate_items));
|
|
|
|
crate_data.insert("paths".to_owned(), Json::Array(crate_paths));
|
2014-03-16 08:08:56 +00:00
|
|
|
|
2016-02-16 18:48:28 +00:00
|
|
|
// Collect the index into a string
|
|
|
|
format!("searchIndex[{}] = {};",
|
|
|
|
as_json(&krate.name),
|
|
|
|
Json::Object(crate_data))
|
2014-05-28 00:12:48 +00:00
|
|
|
}
|
2014-03-16 08:08:56 +00:00
|
|
|
|
2014-05-28 00:12:48 +00:00
|
|
|
fn write_shared(cx: &Context,
|
|
|
|
krate: &clean::Crate,
|
|
|
|
cache: &Cache,
|
2015-09-26 21:59:32 +00:00
|
|
|
search_index: String) -> Result<(), Error> {
|
2014-03-16 08:08:56 +00:00
|
|
|
// Write out the shared files. Note that these are shared among all rustdoc
|
|
|
|
// docs placed in the output directory, so this needs to be a synchronized
|
|
|
|
// operation with respect to all other rustdocs running around.
|
2015-09-26 21:59:32 +00:00
|
|
|
try_err!(mkdir(&cx.dst), &cx.dst);
|
2014-05-28 00:12:48 +00:00
|
|
|
let _lock = ::flock::Lock::new(&cx.dst.join(".lock"));
|
|
|
|
|
|
|
|
// Add all the static files. These may already exist, but we just
|
|
|
|
// overwrite them anyway to make sure that they're fresh and up-to-date.
|
|
|
|
try!(write(cx.dst.join("jquery.js"),
|
2015-07-02 03:52:40 +00:00
|
|
|
include_bytes!("static/jquery-2.1.4.min.js")));
|
2015-09-26 21:59:32 +00:00
|
|
|
try!(write(cx.dst.join("main.js"),
|
|
|
|
include_bytes!("static/main.js")));
|
|
|
|
try!(write(cx.dst.join("playpen.js"),
|
|
|
|
include_bytes!("static/playpen.js")));
|
2015-12-04 00:54:59 +00:00
|
|
|
try!(write(cx.dst.join("rustdoc.css"),
|
|
|
|
include_bytes!("static/rustdoc.css")));
|
2015-09-26 21:59:32 +00:00
|
|
|
try!(write(cx.dst.join("main.css"),
|
2015-12-04 00:54:59 +00:00
|
|
|
include_bytes!("static/styles/main.css")));
|
2014-05-28 00:12:48 +00:00
|
|
|
try!(write(cx.dst.join("normalize.css"),
|
2014-12-21 21:57:09 +00:00
|
|
|
include_bytes!("static/normalize.css")));
|
2014-05-28 00:12:48 +00:00
|
|
|
try!(write(cx.dst.join("FiraSans-Regular.woff"),
|
2014-12-21 21:57:09 +00:00
|
|
|
include_bytes!("static/FiraSans-Regular.woff")));
|
2014-05-28 00:12:48 +00:00
|
|
|
try!(write(cx.dst.join("FiraSans-Medium.woff"),
|
2014-12-21 21:57:09 +00:00
|
|
|
include_bytes!("static/FiraSans-Medium.woff")));
|
2015-09-19 09:42:03 +00:00
|
|
|
try!(write(cx.dst.join("FiraSans-LICENSE.txt"),
|
|
|
|
include_bytes!("static/FiraSans-LICENSE.txt")));
|
2014-05-28 00:12:48 +00:00
|
|
|
try!(write(cx.dst.join("Heuristica-Italic.woff"),
|
2014-12-21 21:57:09 +00:00
|
|
|
include_bytes!("static/Heuristica-Italic.woff")));
|
2015-09-19 09:42:03 +00:00
|
|
|
try!(write(cx.dst.join("Heuristica-LICENSE.txt"),
|
|
|
|
include_bytes!("static/Heuristica-LICENSE.txt")));
|
2014-07-11 07:49:59 +00:00
|
|
|
try!(write(cx.dst.join("SourceSerifPro-Regular.woff"),
|
2014-12-21 21:57:09 +00:00
|
|
|
include_bytes!("static/SourceSerifPro-Regular.woff")));
|
2014-07-08 17:51:06 +00:00
|
|
|
try!(write(cx.dst.join("SourceSerifPro-Bold.woff"),
|
2014-12-21 21:57:09 +00:00
|
|
|
include_bytes!("static/SourceSerifPro-Bold.woff")));
|
2015-09-19 09:42:03 +00:00
|
|
|
try!(write(cx.dst.join("SourceSerifPro-LICENSE.txt"),
|
|
|
|
include_bytes!("static/SourceSerifPro-LICENSE.txt")));
|
2014-07-08 18:26:23 +00:00
|
|
|
try!(write(cx.dst.join("SourceCodePro-Regular.woff"),
|
2014-12-21 21:57:09 +00:00
|
|
|
include_bytes!("static/SourceCodePro-Regular.woff")));
|
2014-07-08 18:26:23 +00:00
|
|
|
try!(write(cx.dst.join("SourceCodePro-Semibold.woff"),
|
2014-12-21 21:57:09 +00:00
|
|
|
include_bytes!("static/SourceCodePro-Semibold.woff")));
|
2015-09-19 09:42:03 +00:00
|
|
|
try!(write(cx.dst.join("SourceCodePro-LICENSE.txt"),
|
|
|
|
include_bytes!("static/SourceCodePro-LICENSE.txt")));
|
|
|
|
try!(write(cx.dst.join("LICENSE-MIT.txt"),
|
|
|
|
include_bytes!("static/LICENSE-MIT.txt")));
|
|
|
|
try!(write(cx.dst.join("LICENSE-APACHE.txt"),
|
|
|
|
include_bytes!("static/LICENSE-APACHE.txt")));
|
2015-09-21 21:40:27 +00:00
|
|
|
try!(write(cx.dst.join("COPYRIGHT.txt"),
|
|
|
|
include_bytes!("static/COPYRIGHT.txt")));
|
2014-05-28 00:12:48 +00:00
|
|
|
|
|
|
|
fn collect(path: &Path, krate: &str,
|
2015-02-27 05:00:43 +00:00
|
|
|
key: &str) -> io::Result<Vec<String>> {
|
2014-05-28 00:12:48 +00:00
|
|
|
let mut ret = Vec::new();
|
|
|
|
if path.exists() {
|
2015-02-27 05:00:43 +00:00
|
|
|
for line in BufReader::new(try!(File::open(path))).lines() {
|
2014-05-28 00:12:48 +00:00
|
|
|
let line = try!(line);
|
2014-11-27 19:19:27 +00:00
|
|
|
if !line.starts_with(key) {
|
2014-05-28 00:12:48 +00:00
|
|
|
continue
|
2014-03-16 08:08:56 +00:00
|
|
|
}
|
2016-02-16 19:00:57 +00:00
|
|
|
if line.starts_with(&format!(r#"{}["{}"]"#, key, krate)) {
|
2014-05-28 00:12:48 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
ret.push(line.to_string());
|
2014-01-30 19:30:21 +00:00
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-05-28 00:12:48 +00:00
|
|
|
return Ok(ret);
|
|
|
|
}
|
2014-05-21 23:41:58 +00:00
|
|
|
|
2014-05-28 00:12:48 +00:00
|
|
|
// Update the search index
|
|
|
|
let dst = cx.dst.join("search-index.js");
|
2015-09-26 21:59:32 +00:00
|
|
|
let all_indexes = try_err!(collect(&dst, &krate.name, "searchIndex"), &dst);
|
|
|
|
let mut w = try_err!(File::create(&dst), &dst);
|
|
|
|
try_err!(writeln!(&mut w, "var searchIndex = {{}};"), &dst);
|
|
|
|
try_err!(writeln!(&mut w, "{}", search_index), &dst);
|
2015-01-31 17:20:46 +00:00
|
|
|
for index in &all_indexes {
|
2015-09-26 21:59:32 +00:00
|
|
|
try_err!(writeln!(&mut w, "{}", *index), &dst);
|
2014-05-28 00:12:48 +00:00
|
|
|
}
|
2015-09-26 21:59:32 +00:00
|
|
|
try_err!(writeln!(&mut w, "initSearch(searchIndex);"), &dst);
|
2014-05-28 00:12:48 +00:00
|
|
|
|
|
|
|
// Update the list of all implementors for traits
|
|
|
|
let dst = cx.dst.join("implementors");
|
2015-09-26 21:59:32 +00:00
|
|
|
try_err!(mkdir(&dst), &dst);
|
2015-01-31 17:20:46 +00:00
|
|
|
for (&did, imps) in &cache.implementors {
|
2014-05-29 20:50:47 +00:00
|
|
|
// Private modules can leak through to this phase of rustdoc, which
|
|
|
|
// could contain implementations for otherwise private types. In some
|
|
|
|
// rare cases we could find an implementation for an item which wasn't
|
|
|
|
// indexed, so we just skip this step in that case.
|
|
|
|
//
|
|
|
|
// FIXME: this is a vague explanation for why this can't be a `get`, in
|
|
|
|
// theory it should be...
|
2014-11-06 17:25:16 +00:00
|
|
|
let &(ref remote_path, remote_item_type) = match cache.paths.get(&did) {
|
2014-05-29 20:50:47 +00:00
|
|
|
Some(p) => p,
|
|
|
|
None => continue,
|
|
|
|
};
|
2014-05-28 00:12:48 +00:00
|
|
|
|
|
|
|
let mut mydst = dst.clone();
|
2015-01-31 17:20:46 +00:00
|
|
|
for part in &remote_path[..remote_path.len() - 1] {
|
2015-02-02 02:53:25 +00:00
|
|
|
mydst.push(part);
|
2015-09-26 21:59:32 +00:00
|
|
|
try_err!(mkdir(&mydst), &mydst);
|
2014-05-28 00:12:48 +00:00
|
|
|
}
|
2015-02-27 05:00:43 +00:00
|
|
|
mydst.push(&format!("{}.{}.js",
|
|
|
|
remote_item_type.to_static_str(),
|
|
|
|
remote_path[remote_path.len() - 1]));
|
2015-09-26 21:59:32 +00:00
|
|
|
let all_implementors = try_err!(collect(&mydst, &krate.name,
|
|
|
|
"implementors"),
|
|
|
|
&mydst);
|
2014-05-28 00:12:48 +00:00
|
|
|
|
2015-09-26 21:59:32 +00:00
|
|
|
try_err!(mkdir(mydst.parent().unwrap()),
|
|
|
|
&mydst.parent().unwrap().to_path_buf());
|
|
|
|
let mut f = BufWriter::new(try_err!(File::create(&mydst), &mydst));
|
|
|
|
try_err!(writeln!(&mut f, "(function() {{var implementors = {{}};"), &mydst);
|
2014-05-28 00:12:48 +00:00
|
|
|
|
2015-01-31 17:20:46 +00:00
|
|
|
for implementor in &all_implementors {
|
2015-09-26 21:59:32 +00:00
|
|
|
try_err!(write!(&mut f, "{}", *implementor), &mydst);
|
2014-03-16 08:08:56 +00:00
|
|
|
}
|
2014-05-21 23:41:58 +00:00
|
|
|
|
2015-09-26 21:59:32 +00:00
|
|
|
try_err!(write!(&mut f, r"implementors['{}'] = [", krate.name), &mydst);
|
2015-01-31 17:20:46 +00:00
|
|
|
for imp in imps {
|
2014-06-01 18:30:53 +00:00
|
|
|
// If the trait and implementation are in the same crate, then
|
|
|
|
// there's no need to emit information about it (there's inlining
|
|
|
|
// going on). If they're in different crates then the crate defining
|
|
|
|
// the trait will be interested in our implementation.
|
|
|
|
if imp.def_id.krate == did.krate { continue }
|
2015-09-26 21:59:32 +00:00
|
|
|
try_err!(write!(&mut f, r#""{}","#, imp.impl_), &mydst);
|
2014-05-21 23:41:58 +00:00
|
|
|
}
|
2015-09-26 21:59:32 +00:00
|
|
|
try_err!(writeln!(&mut f, r"];"), &mydst);
|
|
|
|
try_err!(writeln!(&mut f, "{}", r"
|
2014-05-28 00:12:48 +00:00
|
|
|
if (window.register_implementors) {
|
|
|
|
window.register_implementors(implementors);
|
|
|
|
} else {
|
|
|
|
window.pending_implementors = implementors;
|
|
|
|
}
|
2015-09-26 21:59:32 +00:00
|
|
|
"), &mydst);
|
|
|
|
try_err!(writeln!(&mut f, r"}})()"), &mydst);
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-05-28 00:12:48 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2014-05-28 00:12:48 +00:00
|
|
|
fn render_sources(cx: &mut Context,
|
2015-09-26 21:59:32 +00:00
|
|
|
krate: clean::Crate) -> Result<clean::Crate, Error> {
|
2014-05-28 00:12:48 +00:00
|
|
|
info!("emitting source files");
|
|
|
|
let dst = cx.dst.join("src");
|
2015-09-26 21:59:32 +00:00
|
|
|
try_err!(mkdir(&dst), &dst);
|
2015-02-02 02:53:25 +00:00
|
|
|
let dst = dst.join(&krate.name);
|
2015-09-26 21:59:32 +00:00
|
|
|
try_err!(mkdir(&dst), &dst);
|
2014-05-28 00:12:48 +00:00
|
|
|
let mut folder = SourceCollector {
|
|
|
|
dst: dst,
|
|
|
|
cx: cx,
|
|
|
|
};
|
|
|
|
Ok(folder.fold_crate(krate))
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2013-10-03 17:24:40 +00:00
|
|
|
/// Writes the entire contents of a string to a destination, not attempting to
|
|
|
|
/// catch any errors.
|
2015-09-26 21:59:32 +00:00
|
|
|
fn write(dst: PathBuf, contents: &[u8]) -> Result<(), Error> {
|
|
|
|
Ok(try_err!(try_err!(File::create(&dst), &dst).write_all(contents), &dst))
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2015-05-08 15:12:29 +00:00
|
|
|
/// Makes a directory on the filesystem, failing the thread if an error occurs and
|
2013-10-03 17:24:40 +00:00
|
|
|
/// skipping if the directory already exists.
|
2015-02-27 05:00:43 +00:00
|
|
|
fn mkdir(path: &Path) -> io::Result<()> {
|
2014-01-30 19:30:21 +00:00
|
|
|
if !path.exists() {
|
2015-02-27 05:00:43 +00:00
|
|
|
fs::create_dir(path)
|
2014-01-30 19:30:21 +00:00
|
|
|
} else {
|
|
|
|
Ok(())
|
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2014-12-03 14:57:45 +00:00
|
|
|
/// Returns a documentation-level item type from the item.
|
|
|
|
fn shortty(item: &clean::Item) -> ItemType {
|
|
|
|
ItemType::from_item(item)
|
|
|
|
}
|
|
|
|
|
2013-10-03 17:24:40 +00:00
|
|
|
/// Takes a path to a source file and cleans the path to it. This canonicalizes
|
2013-09-27 00:21:59 +00:00
|
|
|
/// things like ".." to components which preserve the "top down" hierarchy of a
|
2015-03-17 02:44:13 +00:00
|
|
|
/// static HTML tree. Each component in the cleaned path will be passed as an
|
|
|
|
/// argument to `f`. The very last component of the path (ie the file name) will
|
|
|
|
/// be passed to `f` if `keep_filename` is true, and ignored otherwise.
|
2013-09-27 00:21:59 +00:00
|
|
|
// FIXME (#9639): The closure should deal with &[u8] instead of &str
|
2014-12-01 11:46:51 +00:00
|
|
|
// FIXME (#9639): This is too conservative, rejecting non-UTF-8 paths
|
2015-03-17 02:44:13 +00:00
|
|
|
fn clean_srcpath<F>(src_root: &Path, p: &Path, keep_filename: bool, mut f: F) where
|
2014-12-09 20:22:19 +00:00
|
|
|
F: FnMut(&str),
|
|
|
|
{
|
2014-12-01 11:46:51 +00:00
|
|
|
// make it relative, if possible
|
2016-01-15 18:07:52 +00:00
|
|
|
let p = p.strip_prefix(src_root).unwrap_or(p);
|
2014-12-01 11:46:51 +00:00
|
|
|
|
2016-02-23 06:52:43 +00:00
|
|
|
let mut iter = p.components().peekable();
|
|
|
|
|
2015-03-17 02:44:13 +00:00
|
|
|
while let Some(c) = iter.next() {
|
|
|
|
if !keep_filename && iter.peek().is_none() {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-02-23 06:52:43 +00:00
|
|
|
match c {
|
|
|
|
Component::ParentDir => f("up"),
|
|
|
|
Component::Normal(c) => f(c.to_str().unwrap()),
|
|
|
|
_ => continue,
|
2013-09-27 22:12:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-03 17:24:40 +00:00
|
|
|
/// Attempts to find where an external crate is located, given that we're
|
|
|
|
/// rendering in to the specified source destination.
|
2013-10-02 22:39:32 +00:00
|
|
|
fn extern_location(e: &clean::ExternalCrate, dst: &Path) -> ExternalLocation {
|
|
|
|
// See if there's documentation generated into the local directory
|
2015-02-02 02:53:25 +00:00
|
|
|
let local_location = dst.join(&e.name);
|
2013-10-02 22:39:32 +00:00
|
|
|
if local_location.is_dir() {
|
|
|
|
return Local;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Failing that, see if there's an attribute specifying where to find this
|
|
|
|
// external crate
|
2016-02-28 09:12:41 +00:00
|
|
|
e.attrs.list_def("doc").value("html_root_url").map(|url| {
|
|
|
|
let mut url = url.to_owned();
|
|
|
|
if !url.ends_with("/") {
|
|
|
|
url.push('/')
|
2013-10-02 22:39:32 +00:00
|
|
|
}
|
2016-02-28 09:12:41 +00:00
|
|
|
Remote(url)
|
|
|
|
}).unwrap_or(Unknown) // Well, at least we tried.
|
2013-10-02 22:39:32 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 07:16:18 +00:00
|
|
|
impl<'a> DocFolder for SourceCollector<'a> {
|
2013-09-27 22:12:23 +00:00
|
|
|
fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
|
2013-10-03 17:24:40 +00:00
|
|
|
// If we're including source files, and we haven't seen this file yet,
|
|
|
|
// then we need to render it out to the filesystem
|
2016-02-27 06:35:05 +00:00
|
|
|
if self.cx.include_sources
|
|
|
|
// skip all invalid spans
|
|
|
|
&& item.source.filename != ""
|
|
|
|
// macros from other libraries get special filenames which we can
|
|
|
|
// safely ignore
|
|
|
|
&& !(item.source.filename.starts_with("<")
|
|
|
|
&& item.source.filename.ends_with("macros>")) {
|
2013-10-03 17:24:40 +00:00
|
|
|
|
2013-09-30 19:58:18 +00:00
|
|
|
// If it turns out that we couldn't read this file, then we probably
|
|
|
|
// can't read any of the files (generating html output from json or
|
|
|
|
// something like that), so just don't include sources for the
|
|
|
|
// entire crate. The other option is maintaining this mapping on a
|
|
|
|
// per-file basis, but that's probably not worth it...
|
2014-05-12 20:44:59 +00:00
|
|
|
self.cx
|
2016-02-23 06:52:43 +00:00
|
|
|
.include_sources = match self.emit_source(&item.source.filename) {
|
2014-01-30 19:30:21 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(e) => {
|
|
|
|
println!("warning: source code was requested to be rendered, \
|
|
|
|
but processing `{}` had an error: {}",
|
|
|
|
item.source.filename, e);
|
|
|
|
println!(" skipping rendering of source code");
|
|
|
|
false
|
|
|
|
}
|
|
|
|
};
|
2013-09-27 22:12:23 +00:00
|
|
|
}
|
2013-10-03 17:24:40 +00:00
|
|
|
|
2013-09-27 22:12:23 +00:00
|
|
|
self.fold_item_recur(item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-10 07:16:18 +00:00
|
|
|
impl<'a> SourceCollector<'a> {
|
2013-10-03 17:24:40 +00:00
|
|
|
/// Renders the given filename into its corresponding HTML source file.
|
2015-02-27 05:00:43 +00:00
|
|
|
fn emit_source(&mut self, filename: &str) -> io::Result<()> {
|
2015-03-18 16:14:54 +00:00
|
|
|
let p = PathBuf::from(filename);
|
2016-02-27 06:35:05 +00:00
|
|
|
if self.cx.local_sources.contains_key(&p) {
|
|
|
|
// We've already emitted this source
|
|
|
|
return Ok(());
|
|
|
|
}
|
2013-09-27 22:12:23 +00:00
|
|
|
|
2015-02-27 05:00:43 +00:00
|
|
|
let mut contents = Vec::new();
|
2016-02-27 06:35:05 +00:00
|
|
|
try!(File::open(&p).and_then(|mut f| f.read_to_end(&mut contents)));
|
|
|
|
|
2015-02-02 02:53:25 +00:00
|
|
|
let contents = str::from_utf8(&contents).unwrap();
|
2013-09-27 22:12:23 +00:00
|
|
|
|
2014-03-18 00:59:44 +00:00
|
|
|
// Remove the utf-8 BOM if any
|
2014-12-09 22:08:10 +00:00
|
|
|
let contents = if contents.starts_with("\u{feff}") {
|
2015-01-18 00:15:52 +00:00
|
|
|
&contents[3..]
|
2014-03-18 00:59:44 +00:00
|
|
|
} else {
|
2014-07-04 20:38:13 +00:00
|
|
|
contents
|
2014-03-18 00:59:44 +00:00
|
|
|
};
|
|
|
|
|
2013-09-27 22:12:23 +00:00
|
|
|
// Create the intermediate directories
|
|
|
|
let mut cur = self.dst.clone();
|
2015-06-08 14:55:35 +00:00
|
|
|
let mut root_path = String::from("../../");
|
2016-02-27 06:35:05 +00:00
|
|
|
let mut href = String::new();
|
2015-03-17 02:44:13 +00:00
|
|
|
clean_srcpath(&self.cx.src_root, &p, false, |component| {
|
2013-10-06 02:49:32 +00:00
|
|
|
cur.push(component);
|
2014-01-30 19:30:21 +00:00
|
|
|
mkdir(&cur).unwrap();
|
2013-09-27 22:12:23 +00:00
|
|
|
root_path.push_str("../");
|
2016-02-27 06:35:05 +00:00
|
|
|
href.push_str(component);
|
|
|
|
href.push('/');
|
2013-11-21 23:42:55 +00:00
|
|
|
});
|
2015-02-27 05:00:43 +00:00
|
|
|
let mut fname = p.file_name().expect("source has no filename")
|
|
|
|
.to_os_string();
|
2015-03-02 18:46:05 +00:00
|
|
|
fname.push(".html");
|
2015-03-18 16:14:54 +00:00
|
|
|
cur.push(&fname[..]);
|
2016-02-27 06:35:05 +00:00
|
|
|
href.push_str(&fname.to_string_lossy());
|
|
|
|
|
2015-02-27 05:00:43 +00:00
|
|
|
let mut w = BufWriter::new(try!(File::create(&cur)));
|
|
|
|
let title = format!("{} -- source", cur.file_name().unwrap()
|
|
|
|
.to_string_lossy());
|
2014-08-04 20:53:33 +00:00
|
|
|
let desc = format!("Source to the Rust file `{}`.", filename);
|
2013-09-27 22:12:23 +00:00
|
|
|
let page = layout::Page {
|
2015-02-02 02:53:25 +00:00
|
|
|
title: &title,
|
2013-09-27 22:12:23 +00:00
|
|
|
ty: "source",
|
2015-02-02 02:53:25 +00:00
|
|
|
root_path: &root_path,
|
|
|
|
description: &desc,
|
2016-02-28 13:01:43 +00:00
|
|
|
keywords: BASIC_KEYWORDS,
|
2013-09-27 22:12:23 +00:00
|
|
|
};
|
2015-02-27 05:00:43 +00:00
|
|
|
try!(layout::render(&mut w, &self.cx.layout,
|
2014-05-10 21:05:06 +00:00
|
|
|
&page, &(""), &Source(contents)));
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(w.flush());
|
2016-02-27 06:35:05 +00:00
|
|
|
self.cx.local_sources.insert(p, href);
|
|
|
|
Ok(())
|
2013-09-27 22:12:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DocFolder for Cache {
|
2013-09-19 05:18:38 +00:00
|
|
|
fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
|
2014-01-10 22:54:11 +00:00
|
|
|
// If this is a private module, we don't want it in the search index.
|
|
|
|
let orig_privmod = match item.inner {
|
|
|
|
clean::ModuleItem(..) => {
|
|
|
|
let prev = self.privmod;
|
2015-07-31 07:04:06 +00:00
|
|
|
self.privmod = prev || (self.remove_priv && item.visibility != Some(hir::Public));
|
2014-01-10 22:54:11 +00:00
|
|
|
prev
|
|
|
|
}
|
|
|
|
_ => self.privmod,
|
|
|
|
};
|
|
|
|
|
2013-09-19 05:18:38 +00:00
|
|
|
// Register any generics to their corresponding string. This is used
|
|
|
|
// when pretty-printing types
|
|
|
|
match item.inner {
|
2013-11-21 21:17:46 +00:00
|
|
|
clean::StructItem(ref s) => self.generics(&s.generics),
|
|
|
|
clean::EnumItem(ref e) => self.generics(&e.generics),
|
|
|
|
clean::FunctionItem(ref f) => self.generics(&f.generics),
|
2015-05-21 12:17:37 +00:00
|
|
|
clean::TypedefItem(ref t, _) => self.generics(&t.generics),
|
2013-11-21 21:17:46 +00:00
|
|
|
clean::TraitItem(ref t) => self.generics(&t.generics),
|
|
|
|
clean::ImplItem(ref i) => self.generics(&i.generics),
|
|
|
|
clean::TyMethodItem(ref i) => self.generics(&i.generics),
|
|
|
|
clean::MethodItem(ref i) => self.generics(&i.generics),
|
|
|
|
clean::ForeignFunctionItem(ref f) => self.generics(&f.generics),
|
2013-09-19 05:18:38 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Propagate a trait methods' documentation to all implementors of the
|
|
|
|
// trait
|
2014-11-29 21:41:21 +00:00
|
|
|
if let clean::TraitItem(ref t) = item.inner {
|
|
|
|
self.traits.insert(item.def_id, t.clone());
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Collect all the implementors of traits.
|
2014-11-29 21:41:21 +00:00
|
|
|
if let clean::ImplItem(ref i) = item.inner {
|
2016-02-28 11:11:13 +00:00
|
|
|
if let Some(clean::ResolvedPath{ did, .. }) = i.trait_ {
|
|
|
|
self.implementors.entry(did).or_insert(vec![]).push(Implementor {
|
|
|
|
def_id: item.def_id,
|
|
|
|
stability: item.stability.clone(),
|
|
|
|
impl_: i.clone(),
|
|
|
|
});
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Index this method for searching later on
|
2014-11-29 21:41:21 +00:00
|
|
|
if let Some(ref s) = item.name {
|
|
|
|
let (parent, is_method) = match item.inner {
|
2016-02-23 09:24:53 +00:00
|
|
|
clean::AssociatedConstItem(..) |
|
|
|
|
clean::TypedefItem(_, true) if self.parent_is_trait_impl => {
|
|
|
|
// skip associated items in trait impls
|
2016-02-23 08:52:44 +00:00
|
|
|
((None, None), false)
|
|
|
|
}
|
2015-05-08 22:03:42 +00:00
|
|
|
clean::AssociatedTypeItem(..) |
|
|
|
|
clean::AssociatedConstItem(..) |
|
2014-11-29 21:41:21 +00:00
|
|
|
clean::TyMethodItem(..) |
|
|
|
|
clean::StructFieldItem(..) |
|
|
|
|
clean::VariantItem(..) => {
|
|
|
|
((Some(*self.parent_stack.last().unwrap()),
|
2015-01-19 16:07:13 +00:00
|
|
|
Some(&self.stack[..self.stack.len() - 1])),
|
2014-11-29 21:41:21 +00:00
|
|
|
false)
|
|
|
|
}
|
|
|
|
clean::MethodItem(..) => {
|
2015-03-24 23:53:34 +00:00
|
|
|
if self.parent_stack.is_empty() {
|
2014-11-29 21:41:21 +00:00
|
|
|
((None, None), false)
|
|
|
|
} else {
|
|
|
|
let last = self.parent_stack.last().unwrap();
|
|
|
|
let did = *last;
|
|
|
|
let path = match self.paths.get(&did) {
|
2014-12-03 14:57:45 +00:00
|
|
|
Some(&(_, ItemType::Trait)) =>
|
2015-01-19 16:07:13 +00:00
|
|
|
Some(&self.stack[..self.stack.len() - 1]),
|
2015-04-07 02:21:52 +00:00
|
|
|
// The current stack not necessarily has correlation
|
|
|
|
// for where the type was defined. On the other
|
|
|
|
// hand, `paths` always has the right
|
|
|
|
// information if present.
|
2014-12-03 14:57:45 +00:00
|
|
|
Some(&(ref fqp, ItemType::Struct)) |
|
|
|
|
Some(&(ref fqp, ItemType::Enum)) =>
|
2015-01-19 16:07:13 +00:00
|
|
|
Some(&fqp[..fqp.len() - 1]),
|
2015-02-02 02:53:25 +00:00
|
|
|
Some(..) => Some(&*self.stack),
|
2014-11-29 21:41:21 +00:00
|
|
|
None => None
|
|
|
|
};
|
|
|
|
((Some(*last), path), true)
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-11-29 21:41:21 +00:00
|
|
|
}
|
2015-02-02 02:53:25 +00:00
|
|
|
_ => ((None, Some(&*self.stack)), false)
|
2014-11-29 21:41:21 +00:00
|
|
|
};
|
|
|
|
let hidden_field = match item.inner {
|
|
|
|
clean::StructFieldItem(clean::HiddenStructField) => true,
|
|
|
|
_ => false
|
|
|
|
};
|
|
|
|
|
|
|
|
match parent {
|
|
|
|
(parent, Some(path)) if is_method || (!self.privmod && !hidden_field) => {
|
2015-02-25 23:03:06 +00:00
|
|
|
// Needed to determine `self` type.
|
|
|
|
let parent_basename = self.parent_stack.first().and_then(|parent| {
|
|
|
|
match self.paths.get(parent) {
|
|
|
|
Some(&(ref fqp, _)) => Some(fqp[fqp.len() - 1].clone()),
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-02-28 11:11:13 +00:00
|
|
|
// A crate has a module at its root, containing all items,
|
|
|
|
// which should not be indexed. The crate-item itself is
|
|
|
|
// inserted later on when serializing the search-index.
|
2015-12-21 02:21:56 +00:00
|
|
|
if item.def_id.index != CRATE_DEF_INDEX {
|
|
|
|
self.search_index.push(IndexItem {
|
|
|
|
ty: shortty(&item),
|
|
|
|
name: s.to_string(),
|
|
|
|
path: path.join("::").to_string(),
|
2016-02-13 10:27:53 +00:00
|
|
|
desc: Escape(&shorter(item.doc_value())).to_string(),
|
2015-12-21 02:21:56 +00:00
|
|
|
parent: parent,
|
2016-02-16 18:48:28 +00:00
|
|
|
parent_idx: None,
|
2015-12-21 02:21:56 +00:00
|
|
|
search_type: get_index_search_type(&item, parent_basename),
|
|
|
|
});
|
|
|
|
}
|
2014-11-29 21:41:21 +00:00
|
|
|
}
|
|
|
|
(Some(parent), None) if is_method || (!self.privmod && !hidden_field)=> {
|
2015-08-16 10:32:28 +00:00
|
|
|
if parent.is_local() {
|
2014-11-29 21:41:21 +00:00
|
|
|
// We have a parent, but we don't know where they're
|
|
|
|
// defined yet. Wait for later to index this item.
|
2015-09-02 20:11:32 +00:00
|
|
|
self.orphan_methods.push((parent, item.clone()))
|
2014-03-07 09:26:06 +00:00
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-11-29 21:41:21 +00:00
|
|
|
_ => {}
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keep track of the fully qualified path for this item.
|
2016-02-28 11:11:13 +00:00
|
|
|
let pushed = match item.name {
|
|
|
|
Some(ref n) if !n.is_empty() => {
|
2014-05-25 10:17:19 +00:00
|
|
|
self.stack.push(n.to_string());
|
2013-09-19 05:18:38 +00:00
|
|
|
true
|
2016-02-28 11:11:13 +00:00
|
|
|
}
|
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
|
2013-09-19 05:18:38 +00:00
|
|
|
match item.inner {
|
2013-11-28 20:22:53 +00:00
|
|
|
clean::StructItem(..) | clean::EnumItem(..) |
|
|
|
|
clean::TypedefItem(..) | clean::TraitItem(..) |
|
|
|
|
clean::FunctionItem(..) | clean::ModuleItem(..) |
|
2014-05-29 20:50:47 +00:00
|
|
|
clean::ForeignFunctionItem(..) if !self.privmod => {
|
2014-05-23 05:00:18 +00:00
|
|
|
// Reexported items mean that the same id can show up twice
|
|
|
|
// in the rustdoc ast that we're looking at. We know,
|
|
|
|
// however, that a reexported item doesn't show up in the
|
|
|
|
// `public_items` map, so we can skip inserting into the
|
|
|
|
// paths map if there was already an entry present and we're
|
|
|
|
// not a public item.
|
2015-09-04 17:52:28 +00:00
|
|
|
if
|
|
|
|
!self.paths.contains_key(&item.def_id) ||
|
|
|
|
!item.def_id.is_local() ||
|
2015-11-19 11:16:35 +00:00
|
|
|
self.access_levels.is_public(item.def_id)
|
2015-09-04 17:52:28 +00:00
|
|
|
{
|
2014-05-23 05:00:18 +00:00
|
|
|
self.paths.insert(item.def_id,
|
|
|
|
(self.stack.clone(), shortty(&item)));
|
2014-02-17 07:11:09 +00:00
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-02-16 22:35:13 +00:00
|
|
|
// link variants to their parent enum because pages aren't emitted
|
|
|
|
// for each variant
|
2014-05-29 20:50:47 +00:00
|
|
|
clean::VariantItem(..) if !self.privmod => {
|
2014-02-16 22:35:13 +00:00
|
|
|
let mut stack = self.stack.clone();
|
|
|
|
stack.pop();
|
2014-12-03 14:57:45 +00:00
|
|
|
self.paths.insert(item.def_id, (stack, ItemType::Enum));
|
2014-02-16 22:35:13 +00:00
|
|
|
}
|
2014-06-04 00:55:30 +00:00
|
|
|
|
|
|
|
clean::PrimitiveItem(..) if item.visibility.is_some() => {
|
|
|
|
self.paths.insert(item.def_id, (self.stack.clone(),
|
|
|
|
shortty(&item)));
|
|
|
|
}
|
|
|
|
|
2013-09-19 05:18:38 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Maintain the parent stack
|
2016-02-23 08:52:44 +00:00
|
|
|
let orig_parent_is_trait_impl = self.parent_is_trait_impl;
|
2013-09-19 05:18:38 +00:00
|
|
|
let parent_pushed = match item.inner {
|
2013-11-28 20:22:53 +00:00
|
|
|
clean::TraitItem(..) | clean::EnumItem(..) | clean::StructItem(..) => {
|
2014-05-23 05:00:18 +00:00
|
|
|
self.parent_stack.push(item.def_id);
|
2016-02-23 08:52:44 +00:00
|
|
|
self.parent_is_trait_impl = false;
|
2014-05-03 09:08:58 +00:00
|
|
|
true
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
clean::ImplItem(ref i) => {
|
2016-02-23 08:52:44 +00:00
|
|
|
self.parent_is_trait_impl = i.trait_.is_some();
|
2013-09-19 05:18:38 +00:00
|
|
|
match i.for_ {
|
2014-05-09 20:52:17 +00:00
|
|
|
clean::ResolvedPath{ did, .. } => {
|
2014-05-23 05:00:18 +00:00
|
|
|
self.parent_stack.push(did);
|
|
|
|
true
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2015-04-08 00:35:23 +00:00
|
|
|
ref t => {
|
|
|
|
match t.primitive_type() {
|
|
|
|
Some(prim) => {
|
2015-09-17 18:29:59 +00:00
|
|
|
let did = DefId::local(prim.to_def_index());
|
2015-04-08 00:35:23 +00:00
|
|
|
self.parent_stack.push(did);
|
|
|
|
true
|
|
|
|
}
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => false
|
|
|
|
};
|
|
|
|
|
|
|
|
// Once we've recursively found all the generics, then hoard off all the
|
|
|
|
// implementations elsewhere
|
2016-02-28 11:11:13 +00:00
|
|
|
let ret = self.fold_item_recur(item).and_then(|item| {
|
|
|
|
if let clean::Item { attrs, inner: clean::ImplItem(i), .. } = item {
|
|
|
|
// Figure out the id of this impl. This may map to a
|
|
|
|
// primitive rather than always to a struct/enum.
|
|
|
|
let did = match i.for_ {
|
|
|
|
clean::ResolvedPath { did, .. } |
|
|
|
|
clean::BorrowedRef {
|
|
|
|
type_: box clean::ResolvedPath { did, .. }, ..
|
|
|
|
} => {
|
|
|
|
Some(did)
|
|
|
|
}
|
2014-11-29 21:41:21 +00:00
|
|
|
|
2016-02-28 11:11:13 +00:00
|
|
|
ref t => {
|
|
|
|
t.primitive_type().and_then(|t| {
|
|
|
|
self.primitive_locations.get(&t).map(|n| {
|
|
|
|
let id = t.to_def_index();
|
|
|
|
DefId { krate: *n, index: id }
|
|
|
|
})
|
|
|
|
})
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2016-02-28 11:11:13 +00:00
|
|
|
};
|
2014-01-10 22:54:11 +00:00
|
|
|
|
2016-02-28 11:11:13 +00:00
|
|
|
if let Some(did) = did {
|
|
|
|
self.impls.entry(did).or_insert(vec![]).push(Impl {
|
|
|
|
impl_: i,
|
2016-02-28 09:12:41 +00:00
|
|
|
dox: attrs.value("doc").map(|s|s.to_owned()),
|
2016-02-28 11:11:13 +00:00
|
|
|
stability: item.stability.clone(),
|
|
|
|
});
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2016-02-28 11:11:13 +00:00
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(item)
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2016-02-28 11:11:13 +00:00
|
|
|
});
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2013-12-23 15:20:52 +00:00
|
|
|
if pushed { self.stack.pop().unwrap(); }
|
|
|
|
if parent_pushed { self.parent_stack.pop().unwrap(); }
|
2014-01-10 22:54:11 +00:00
|
|
|
self.privmod = orig_privmod;
|
2016-02-23 08:52:44 +00:00
|
|
|
self.parent_is_trait_impl = orig_parent_is_trait_impl;
|
2013-09-19 05:18:38 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-10 07:16:18 +00:00
|
|
|
impl<'a> Cache {
|
2013-09-19 05:18:38 +00:00
|
|
|
fn generics(&mut self, generics: &clean::Generics) {
|
2015-01-31 17:20:46 +00:00
|
|
|
for typ in &generics.type_params {
|
2014-05-03 09:08:58 +00:00
|
|
|
self.typarams.insert(typ.did, typ.name.clone());
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Context {
|
2013-10-03 17:24:40 +00:00
|
|
|
/// Recurse in the directory structure and change the "root path" to make
|
|
|
|
/// sure it always points to the top (relatively)
|
2014-12-09 20:22:19 +00:00
|
|
|
fn recurse<T, F>(&mut self, s: String, f: F) -> T where
|
|
|
|
F: FnOnce(&mut Context) -> T,
|
|
|
|
{
|
2015-03-24 23:53:34 +00:00
|
|
|
if s.is_empty() {
|
2014-12-20 08:09:35 +00:00
|
|
|
panic!("Unexpected empty destination: {:?}", self.current);
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2013-09-27 00:21:59 +00:00
|
|
|
let prev = self.dst.clone();
|
2015-02-02 02:53:25 +00:00
|
|
|
self.dst.push(&s);
|
2013-09-19 05:18:38 +00:00
|
|
|
self.root_path.push_str("../");
|
|
|
|
self.current.push(s);
|
|
|
|
|
2013-12-17 16:19:14 +00:00
|
|
|
info!("Recursing into {}", self.dst.display());
|
|
|
|
|
2014-01-30 19:30:21 +00:00
|
|
|
mkdir(&self.dst).unwrap();
|
2013-09-19 05:18:38 +00:00
|
|
|
let ret = f(self);
|
|
|
|
|
2013-12-17 16:19:14 +00:00
|
|
|
info!("Recursed; leaving {}", self.dst.display());
|
|
|
|
|
2013-09-19 05:18:38 +00:00
|
|
|
// Go back to where we were at
|
|
|
|
self.dst = prev;
|
|
|
|
let len = self.root_path.len();
|
|
|
|
self.root_path.truncate(len - 3);
|
2013-12-23 15:20:52 +00:00
|
|
|
self.current.pop().unwrap();
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-12-06 02:19:06 +00:00
|
|
|
/// Main method for rendering a crate.
|
|
|
|
///
|
|
|
|
/// This currently isn't parallelized, but it'd be pretty easy to add
|
|
|
|
/// parallelization to this function.
|
2015-09-26 21:59:32 +00:00
|
|
|
fn krate(self, mut krate: clean::Crate) -> Result<(), Error> {
|
2014-02-05 21:15:24 +00:00
|
|
|
let mut item = match krate.module.take() {
|
2013-09-19 05:18:38 +00:00
|
|
|
Some(i) => i,
|
2014-01-30 19:30:21 +00:00
|
|
|
None => return Ok(())
|
2013-09-19 05:18:38 +00:00
|
|
|
};
|
2014-02-05 21:15:24 +00:00
|
|
|
item.name = Some(krate.name);
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2014-07-04 07:51:46 +00:00
|
|
|
// render the crate documentation
|
2014-03-05 23:28:08 +00:00
|
|
|
let mut work = vec!((self, item));
|
2013-12-23 15:20:52 +00:00
|
|
|
loop {
|
|
|
|
match work.pop() {
|
2014-02-19 18:07:49 +00:00
|
|
|
Some((mut cx, item)) => try!(cx.item(item, |cx, item| {
|
2013-12-23 15:20:52 +00:00
|
|
|
work.push((cx.clone(), item));
|
2014-01-30 19:30:21 +00:00
|
|
|
})),
|
2013-12-23 15:20:52 +00:00
|
|
|
None => break,
|
|
|
|
}
|
2013-12-18 17:26:19 +00:00
|
|
|
}
|
2014-07-04 07:51:46 +00:00
|
|
|
|
2014-01-30 19:30:21 +00:00
|
|
|
Ok(())
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2014-08-01 23:40:21 +00:00
|
|
|
/// Non-parallelized version of rendering an item. This will take the input
|
2013-10-03 17:24:40 +00:00
|
|
|
/// item, render its contents, and then invoke the specified closure with
|
|
|
|
/// all sub-items which need to be rendered.
|
|
|
|
///
|
|
|
|
/// The rendering driver uses this closure to queue up more work.
|
2015-09-26 21:59:32 +00:00
|
|
|
fn item<F>(&mut self, item: clean::Item, mut f: F) -> Result<(), Error> where
|
2014-12-09 20:22:19 +00:00
|
|
|
F: FnMut(&mut Context, clean::Item),
|
|
|
|
{
|
2015-02-27 05:00:43 +00:00
|
|
|
fn render(w: File, cx: &Context, it: &clean::Item,
|
|
|
|
pushname: bool) -> io::Result<()> {
|
2013-09-19 05:18:38 +00:00
|
|
|
// A little unfortunate that this is done like this, but it sure
|
|
|
|
// does make formatting *a lot* nicer.
|
2014-11-14 22:20:57 +00:00
|
|
|
CURRENT_LOCATION_KEY.with(|slot| {
|
|
|
|
*slot.borrow_mut() = cx.current.clone();
|
|
|
|
});
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2015-07-10 12:19:21 +00:00
|
|
|
let mut title = cx.current.join("::");
|
2013-09-19 05:18:38 +00:00
|
|
|
if pushname {
|
2015-03-24 23:54:09 +00:00
|
|
|
if !title.is_empty() {
|
2014-04-02 23:54:22 +00:00
|
|
|
title.push_str("::");
|
|
|
|
}
|
2015-02-02 02:53:25 +00:00
|
|
|
title.push_str(it.name.as_ref().unwrap());
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
title.push_str(" - Rust");
|
2014-08-04 20:53:33 +00:00
|
|
|
let tyname = shortty(it).to_static_str();
|
2016-02-28 11:23:07 +00:00
|
|
|
let desc = if it.is_crate() {
|
2014-08-04 20:53:33 +00:00
|
|
|
format!("API documentation for the Rust `{}` crate.",
|
|
|
|
cx.layout.krate)
|
|
|
|
} else {
|
|
|
|
format!("API documentation for the Rust `{}` {} in crate `{}`.",
|
2014-10-15 06:05:01 +00:00
|
|
|
it.name.as_ref().unwrap(), tyname, cx.layout.krate)
|
2014-08-04 20:53:33 +00:00
|
|
|
};
|
2014-08-04 21:30:06 +00:00
|
|
|
let keywords = make_item_keywords(it);
|
2013-09-19 05:18:38 +00:00
|
|
|
let page = layout::Page {
|
2014-08-04 20:53:33 +00:00
|
|
|
ty: tyname,
|
2015-02-02 02:53:25 +00:00
|
|
|
root_path: &cx.root_path,
|
|
|
|
title: &title,
|
|
|
|
description: &desc,
|
|
|
|
keywords: &keywords,
|
2013-09-19 05:18:38 +00:00
|
|
|
};
|
|
|
|
|
2015-12-02 23:06:26 +00:00
|
|
|
reset_ids();
|
2014-03-04 19:24:20 +00:00
|
|
|
|
2013-09-19 05:18:38 +00:00
|
|
|
// We have a huge number of calls to write, so try to alleviate some
|
|
|
|
// of the pain by using a buffered writer instead of invoking the
|
2014-09-02 05:35:58 +00:00
|
|
|
// write syscall all the time.
|
2015-02-27 05:00:43 +00:00
|
|
|
let mut writer = BufWriter::new(w);
|
2014-05-29 20:50:47 +00:00
|
|
|
if !cx.render_redirect_pages {
|
|
|
|
try!(layout::render(&mut writer, &cx.layout, &page,
|
|
|
|
&Sidebar{ cx: cx, item: it },
|
|
|
|
&Item{ cx: cx, item: it }));
|
|
|
|
} else {
|
2014-12-11 03:46:38 +00:00
|
|
|
let mut url = repeat("../").take(cx.current.len())
|
|
|
|
.collect::<String>();
|
2014-11-14 22:20:57 +00:00
|
|
|
match cache().paths.get(&it.def_id) {
|
2014-05-29 20:50:47 +00:00
|
|
|
Some(&(ref names, _)) => {
|
2015-01-31 17:20:46 +00:00
|
|
|
for name in &names[..names.len() - 1] {
|
2015-02-02 02:53:25 +00:00
|
|
|
url.push_str(name);
|
2014-05-29 20:50:47 +00:00
|
|
|
url.push_str("/");
|
|
|
|
}
|
2015-02-02 02:53:25 +00:00
|
|
|
url.push_str(&item_path(it));
|
|
|
|
try!(layout::redirect(&mut writer, &url));
|
2014-05-29 20:50:47 +00:00
|
|
|
}
|
|
|
|
None => {}
|
|
|
|
}
|
|
|
|
}
|
2014-01-30 19:30:21 +00:00
|
|
|
writer.flush()
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2014-06-04 00:55:30 +00:00
|
|
|
// Private modules may survive the strip-private pass if they
|
|
|
|
// contain impls for public types. These modules can also
|
|
|
|
// contain items such as publicly reexported structures.
|
|
|
|
//
|
|
|
|
// External crates will provide links to these structures, so
|
|
|
|
// these modules are recursed into, but not rendered normally (a
|
|
|
|
// flag on the context).
|
|
|
|
if !self.render_redirect_pages {
|
2014-11-10 00:09:17 +00:00
|
|
|
self.render_redirect_pages = self.ignore_private_item(&item);
|
2014-06-04 00:55:30 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 05:18:38 +00:00
|
|
|
match item.inner {
|
2013-09-24 20:56:52 +00:00
|
|
|
// modules are special because they add a namespace. We also need to
|
|
|
|
// recurse into the items of the module as well.
|
2013-11-28 20:22:53 +00:00
|
|
|
clean::ModuleItem(..) => {
|
2014-08-19 00:52:38 +00:00
|
|
|
let name = item.name.as_ref().unwrap().to_string();
|
2013-12-05 05:28:47 +00:00
|
|
|
let mut item = Some(item);
|
2013-11-21 23:42:55 +00:00
|
|
|
self.recurse(name, |this| {
|
2014-08-19 00:52:38 +00:00
|
|
|
let item = item.take().unwrap();
|
2015-09-26 21:59:32 +00:00
|
|
|
let joint_dst = this.dst.join("index.html");
|
|
|
|
let dst = try_err!(File::create(&joint_dst), &joint_dst);
|
|
|
|
try_err!(render(dst, this, &item, false), &joint_dst);
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
|
|
let m = match item.inner {
|
|
|
|
clean::ModuleItem(m) => m,
|
|
|
|
_ => unreachable!()
|
|
|
|
};
|
2015-03-05 07:35:43 +00:00
|
|
|
|
|
|
|
// render sidebar-items.js used throughout this module
|
|
|
|
{
|
|
|
|
let items = this.build_sidebar_items(&m);
|
|
|
|
let js_dst = this.dst.join("sidebar-items.js");
|
2015-09-26 21:59:32 +00:00
|
|
|
let mut js_out = BufWriter::new(try_err!(File::create(&js_dst), &js_dst));
|
|
|
|
try_err!(write!(&mut js_out, "initSidebarItems({});",
|
2016-02-16 19:00:57 +00:00
|
|
|
as_json(&items)), &js_dst);
|
2015-03-05 07:35:43 +00:00
|
|
|
}
|
|
|
|
|
2015-02-01 01:03:04 +00:00
|
|
|
for item in m.items {
|
2013-12-18 17:26:19 +00:00
|
|
|
f(this,item);
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-01-30 19:30:21 +00:00
|
|
|
Ok(())
|
2013-11-21 23:42:55 +00:00
|
|
|
})
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2013-09-24 20:56:52 +00:00
|
|
|
|
|
|
|
// Things which don't have names (like impls) don't get special
|
|
|
|
// pages dedicated to them.
|
2013-09-19 05:18:38 +00:00
|
|
|
_ if item.name.is_some() => {
|
2015-09-26 21:59:32 +00:00
|
|
|
let joint_dst = self.dst.join(&item_path(&item));
|
|
|
|
|
|
|
|
let dst = try_err!(File::create(&joint_dst), &joint_dst);
|
|
|
|
try_err!(render(dst, self, &item, true), &joint_dst);
|
|
|
|
Ok(())
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2013-09-24 20:56:52 +00:00
|
|
|
|
2014-01-30 19:30:21 +00:00
|
|
|
_ => Ok(())
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-10 00:09:17 +00:00
|
|
|
|
2015-04-16 10:14:45 +00:00
|
|
|
fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap<String, Vec<NameDoc>> {
|
|
|
|
// BTreeMap instead of HashMap to get a sorted output
|
|
|
|
let mut map = BTreeMap::new();
|
2015-01-31 17:20:46 +00:00
|
|
|
for item in &m.items {
|
2014-11-10 00:09:17 +00:00
|
|
|
if self.ignore_private_item(item) { continue }
|
|
|
|
|
|
|
|
let short = shortty(item).to_static_str();
|
|
|
|
let myname = match item.name {
|
|
|
|
None => continue,
|
|
|
|
Some(ref s) => s.to_string(),
|
|
|
|
};
|
2015-01-04 19:07:32 +00:00
|
|
|
let short = short.to_string();
|
2015-03-20 17:43:01 +00:00
|
|
|
map.entry(short).or_insert(vec![])
|
2015-03-01 14:42:11 +00:00
|
|
|
.push((myname, Some(plain_summary_line(item.doc_value()))));
|
2014-11-10 00:09:17 +00:00
|
|
|
}
|
|
|
|
|
2015-02-01 01:02:00 +00:00
|
|
|
for (_, items) in &mut map {
|
2014-11-27 21:49:29 +00:00
|
|
|
items.sort();
|
2014-11-10 00:09:17 +00:00
|
|
|
}
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ignore_private_item(&self, it: &clean::Item) -> bool {
|
|
|
|
match it.inner {
|
|
|
|
clean::ModuleItem(ref m) => {
|
2015-03-24 23:53:34 +00:00
|
|
|
(m.items.is_empty() &&
|
2015-04-06 23:43:55 +00:00
|
|
|
it.doc_value().is_none() &&
|
2015-07-31 07:04:06 +00:00
|
|
|
it.visibility != Some(hir::Public)) ||
|
|
|
|
(self.passes.contains("strip-private") && it.visibility != Some(hir::Public))
|
2014-11-10 00:09:17 +00:00
|
|
|
}
|
2015-07-31 07:04:06 +00:00
|
|
|
clean::PrimitiveItem(..) => it.visibility != Some(hir::Public),
|
2014-11-10 00:09:17 +00:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 07:16:18 +00:00
|
|
|
impl<'a> Item<'a> {
|
2013-09-19 05:18:38 +00:00
|
|
|
fn ismodule(&self) -> bool {
|
|
|
|
match self.item.inner {
|
2013-11-28 20:22:53 +00:00
|
|
|
clean::ModuleItem(..) => true, _ => false
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-03 00:08:11 +00:00
|
|
|
|
2014-05-24 18:56:38 +00:00
|
|
|
/// Generate a url appropriate for an `href` attribute back to the source of
|
|
|
|
/// this item.
|
|
|
|
///
|
|
|
|
/// The url generated, when clicked, will redirect the browser back to the
|
|
|
|
/// original source code.
|
|
|
|
///
|
|
|
|
/// If `None` is returned, then a source link couldn't be generated. This
|
|
|
|
/// may happen, for example, with externally inlined items where the source
|
|
|
|
/// of their crate documentation isn't known.
|
2016-02-27 06:35:05 +00:00
|
|
|
fn href(&self) -> Option<String> {
|
2015-04-13 22:25:40 +00:00
|
|
|
let href = if self.item.source.loline == self.item.source.hiline {
|
|
|
|
format!("{}", self.item.source.loline)
|
|
|
|
} else {
|
|
|
|
format!("{}-{}", self.item.source.loline, self.item.source.hiline)
|
|
|
|
};
|
|
|
|
|
|
|
|
// First check to see if this is an imported macro source. In this case
|
|
|
|
// we need to handle it specially as cross-crate inlined macros have...
|
|
|
|
// odd locations!
|
|
|
|
let imported_macro_from = match self.item.inner {
|
|
|
|
clean::MacroItem(ref m) => m.imported_from.as_ref(),
|
|
|
|
_ => None,
|
|
|
|
};
|
|
|
|
if let Some(krate) = imported_macro_from {
|
|
|
|
let cache = cache();
|
|
|
|
let root = cache.extern_locations.values().find(|&&(ref n, _)| {
|
|
|
|
*krate == *n
|
|
|
|
}).map(|l| &l.1);
|
|
|
|
let root = match root {
|
|
|
|
Some(&Remote(ref s)) => s.to_string(),
|
|
|
|
Some(&Local) => self.cx.root_path.clone(),
|
|
|
|
None | Some(&Unknown) => return None,
|
|
|
|
};
|
|
|
|
Some(format!("{root}/{krate}/macro.{name}.html?gotomacrosrc=1",
|
|
|
|
root = root,
|
|
|
|
krate = krate,
|
|
|
|
name = self.item.name.as_ref().unwrap()))
|
|
|
|
|
2014-05-24 18:56:38 +00:00
|
|
|
// If this item is part of the local crate, then we're guaranteed to
|
|
|
|
// know the span, so we plow forward and generate a proper url. The url
|
|
|
|
// has anchors for the line numbers that we're linking to.
|
2015-08-16 10:32:28 +00:00
|
|
|
} else if self.item.def_id.is_local() {
|
2016-02-27 06:35:05 +00:00
|
|
|
self.cx.local_sources.get(&PathBuf::from(&self.item.source.filename)).map(|path| {
|
2016-03-08 07:07:57 +00:00
|
|
|
format!("{root}src/{krate}/{path}#{href}",
|
2016-02-27 06:35:05 +00:00
|
|
|
root = self.cx.root_path,
|
|
|
|
krate = self.cx.layout.krate,
|
|
|
|
path = path,
|
|
|
|
href = href)
|
|
|
|
})
|
2014-05-24 18:56:38 +00:00
|
|
|
// If this item is not part of the local crate, then things get a little
|
|
|
|
// trickier. We don't actually know the span of the external item, but
|
|
|
|
// we know that the documentation on the other end knows the span!
|
|
|
|
//
|
|
|
|
// In this case, we generate a link to the *documentation* for this type
|
|
|
|
// in the original crate. There's an extra URL parameter which says that
|
|
|
|
// we want to go somewhere else, and the JS on the destination page will
|
|
|
|
// pick it up and instantly redirect the browser to the source code.
|
|
|
|
//
|
|
|
|
// If we don't know where the external documentation for this crate is
|
|
|
|
// located, then we return `None`.
|
2014-05-03 00:08:11 +00:00
|
|
|
} else {
|
2014-11-14 22:20:57 +00:00
|
|
|
let cache = cache();
|
2015-03-22 01:15:47 +00:00
|
|
|
let path = &cache.external_paths[&self.item.def_id];
|
|
|
|
let root = match cache.extern_locations[&self.item.def_id.krate] {
|
2015-04-13 22:25:40 +00:00
|
|
|
(_, Remote(ref s)) => s.to_string(),
|
|
|
|
(_, Local) => self.cx.root_path.clone(),
|
|
|
|
(_, Unknown) => return None,
|
2014-05-24 03:17:27 +00:00
|
|
|
};
|
2014-05-27 12:52:00 +00:00
|
|
|
Some(format!("{root}{path}/{file}?gotosrc={goto}",
|
2014-05-24 03:17:27 +00:00
|
|
|
root = root,
|
2015-07-10 12:19:21 +00:00
|
|
|
path = path[..path.len() - 1].join("/"),
|
2014-05-24 03:17:27 +00:00
|
|
|
file = item_path(self.item),
|
2015-09-17 18:29:59 +00:00
|
|
|
goto = self.item.def_id.index.as_usize()))
|
2014-05-24 03:17:27 +00:00
|
|
|
}
|
2014-05-03 00:08:11 +00:00
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2014-07-04 07:51:46 +00:00
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
impl<'a> fmt::Display for Item<'a> {
|
2014-02-05 12:55:13 +00:00
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
2013-09-19 05:18:38 +00:00
|
|
|
// Write the breadcrumb trail header for the top
|
2014-09-24 04:47:25 +00:00
|
|
|
try!(write!(fmt, "\n<h1 class='fqn'><span class='in-band'>"));
|
2014-02-05 12:55:13 +00:00
|
|
|
match self.item.inner {
|
2014-02-28 21:33:45 +00:00
|
|
|
clean::ModuleItem(ref m) => if m.is_crate {
|
2014-05-10 21:05:06 +00:00
|
|
|
try!(write!(fmt, "Crate "));
|
2014-02-28 21:33:45 +00:00
|
|
|
} else {
|
2014-05-10 21:05:06 +00:00
|
|
|
try!(write!(fmt, "Module "));
|
2014-02-28 21:33:45 +00:00
|
|
|
},
|
2014-05-10 21:05:06 +00:00
|
|
|
clean::FunctionItem(..) => try!(write!(fmt, "Function ")),
|
|
|
|
clean::TraitItem(..) => try!(write!(fmt, "Trait ")),
|
|
|
|
clean::StructItem(..) => try!(write!(fmt, "Struct ")),
|
|
|
|
clean::EnumItem(..) => try!(write!(fmt, "Enum ")),
|
2014-05-29 02:53:37 +00:00
|
|
|
clean::PrimitiveItem(..) => try!(write!(fmt, "Primitive Type ")),
|
2013-09-19 05:18:38 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
2014-05-29 02:53:37 +00:00
|
|
|
let is_primitive = match self.item.inner {
|
|
|
|
clean::PrimitiveItem(..) => true,
|
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
if !is_primitive {
|
2015-02-02 02:53:25 +00:00
|
|
|
let cur = &self.cx.current;
|
2014-05-29 02:53:37 +00:00
|
|
|
let amt = if self.ismodule() { cur.len() - 1 } else { cur.len() };
|
|
|
|
for (i, component) in cur.iter().enumerate().take(amt) {
|
2014-08-17 18:28:20 +00:00
|
|
|
try!(write!(fmt, "<a href='{}index.html'>{}</a>::<wbr>",
|
2014-12-11 03:46:38 +00:00
|
|
|
repeat("../").take(cur.len() - i - 1)
|
|
|
|
.collect::<String>(),
|
2015-02-02 02:53:25 +00:00
|
|
|
component));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-10 21:05:06 +00:00
|
|
|
try!(write!(fmt, "<a class='{}' href=''>{}</a>",
|
2015-02-02 02:53:25 +00:00
|
|
|
shortty(self.item), self.item.name.as_ref().unwrap()));
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2014-09-24 04:47:25 +00:00
|
|
|
try!(write!(fmt, "</span>")); // in-band
|
|
|
|
try!(write!(fmt, "<span class='out-of-band'>"));
|
2014-07-31 01:31:34 +00:00
|
|
|
try!(write!(fmt,
|
|
|
|
r##"<span id='render-detail'>
|
2015-05-07 07:53:21 +00:00
|
|
|
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
|
|
|
|
[<span class='inner'>−</span>]
|
|
|
|
</a>
|
2014-07-31 01:31:34 +00:00
|
|
|
</span>"##));
|
|
|
|
|
2014-04-25 08:34:32 +00:00
|
|
|
// Write `src` tag
|
2014-05-24 18:56:38 +00:00
|
|
|
//
|
|
|
|
// When this item is part of a `pub use` in a downstream crate, the
|
|
|
|
// [src] link in the downstream documentation will actually come back to
|
|
|
|
// this page, and this link will be auto-clicked. The `id` attribute is
|
|
|
|
// used to find the link to auto-click.
|
2014-05-29 02:53:37 +00:00
|
|
|
if self.cx.include_sources && !is_primitive {
|
2016-02-28 11:11:13 +00:00
|
|
|
if let Some(l) = self.href() {
|
|
|
|
try!(write!(fmt, "<a id='src-{}' class='srclink' \
|
|
|
|
href='{}' title='{}'>[src]</a>",
|
|
|
|
self.item.def_id.index.as_usize(), l, "goto source code"));
|
2014-05-24 03:17:27 +00:00
|
|
|
}
|
2014-04-12 19:39:12 +00:00
|
|
|
}
|
2014-07-04 07:51:46 +00:00
|
|
|
|
2014-09-24 04:47:25 +00:00
|
|
|
try!(write!(fmt, "</span>")); // out-of-band
|
2014-07-04 07:51:46 +00:00
|
|
|
|
2014-05-10 21:05:06 +00:00
|
|
|
try!(write!(fmt, "</h1>\n"));
|
2014-04-12 19:39:12 +00:00
|
|
|
|
2014-02-05 12:55:13 +00:00
|
|
|
match self.item.inner {
|
2014-03-05 23:28:08 +00:00
|
|
|
clean::ModuleItem(ref m) => {
|
2015-02-02 02:53:25 +00:00
|
|
|
item_module(fmt, self.cx, self.item, &m.items)
|
2014-03-05 23:28:08 +00:00
|
|
|
}
|
2013-09-26 18:57:25 +00:00
|
|
|
clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f) =>
|
2015-08-16 15:05:18 +00:00
|
|
|
item_function(fmt, self.cx, self.item, f),
|
2014-05-21 23:41:58 +00:00
|
|
|
clean::TraitItem(ref t) => item_trait(fmt, self.cx, self.item, t),
|
2015-08-16 15:05:18 +00:00
|
|
|
clean::StructItem(ref s) => item_struct(fmt, self.cx, self.item, s),
|
|
|
|
clean::EnumItem(ref e) => item_enum(fmt, self.cx, self.item, e),
|
|
|
|
clean::TypedefItem(ref t, _) => item_typedef(fmt, self.cx, self.item, t),
|
|
|
|
clean::MacroItem(ref m) => item_macro(fmt, self.cx, self.item, m),
|
|
|
|
clean::PrimitiveItem(ref p) => item_primitive(fmt, self.cx, self.item, p),
|
2014-12-03 15:56:45 +00:00
|
|
|
clean::StaticItem(ref i) | clean::ForeignStaticItem(ref i) =>
|
2015-08-16 15:05:18 +00:00
|
|
|
item_static(fmt, self.cx, self.item, i),
|
|
|
|
clean::ConstantItem(ref c) => item_constant(fmt, self.cx, self.item, c),
|
2014-01-30 19:30:21 +00:00
|
|
|
_ => Ok(())
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 23:57:53 +00:00
|
|
|
fn item_path(item: &clean::Item) -> String {
|
2013-09-19 05:18:38 +00:00
|
|
|
match item.inner {
|
2014-05-12 20:44:59 +00:00
|
|
|
clean::ModuleItem(..) => {
|
2014-10-15 06:05:01 +00:00
|
|
|
format!("{}/index.html", item.name.as_ref().unwrap())
|
2014-05-12 20:44:59 +00:00
|
|
|
}
|
|
|
|
_ => {
|
2014-05-28 03:44:58 +00:00
|
|
|
format!("{}.{}.html",
|
|
|
|
shortty(item).to_static_str(),
|
2014-10-15 06:05:01 +00:00
|
|
|
*item.name.as_ref().unwrap())
|
2014-05-12 20:44:59 +00:00
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 23:57:53 +00:00
|
|
|
fn full_path(cx: &Context, item: &clean::Item) -> String {
|
2015-07-10 12:19:21 +00:00
|
|
|
let mut s = cx.current.join("::");
|
2013-09-19 05:18:38 +00:00
|
|
|
s.push_str("::");
|
2015-02-02 02:53:25 +00:00
|
|
|
s.push_str(item.name.as_ref().unwrap());
|
2014-05-12 20:44:59 +00:00
|
|
|
return s
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2015-03-13 22:45:39 +00:00
|
|
|
fn shorter<'a>(s: Option<&'a str>) -> String {
|
2013-09-19 05:18:38 +00:00
|
|
|
match s {
|
2015-03-13 22:45:39 +00:00
|
|
|
Some(s) => s.lines().take_while(|line|{
|
|
|
|
(*line).chars().any(|chr|{
|
|
|
|
!chr.is_whitespace()
|
|
|
|
})
|
2015-07-10 12:19:21 +00:00
|
|
|
}).collect::<Vec<_>>().join("\n"),
|
2015-03-13 22:45:39 +00:00
|
|
|
None => "".to_string()
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-23 01:58:38 +00:00
|
|
|
#[inline]
|
2015-03-10 12:55:09 +00:00
|
|
|
fn plain_summary_line(s: Option<&str>) -> String {
|
2016-02-26 16:39:37 +00:00
|
|
|
let line = shorter(s).replace("\n", " ");
|
|
|
|
markdown::plain_summary_line(&line[..])
|
2014-12-23 01:58:38 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 15:05:18 +00:00
|
|
|
fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Result {
|
|
|
|
if let Some(s) = short_stability(item, cx, true) {
|
2015-04-13 18:55:00 +00:00
|
|
|
try!(write!(w, "<div class='stability'>{}</div>", s));
|
|
|
|
}
|
|
|
|
if let Some(s) = item.doc_value() {
|
|
|
|
try!(write!(w, "<div class='docblock'>{}</div>", Markdown(s)));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-01-30 19:30:21 +00:00
|
|
|
Ok(())
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2014-05-10 21:05:06 +00:00
|
|
|
fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
2014-01-30 19:30:21 +00:00
|
|
|
item: &clean::Item, items: &[clean::Item]) -> fmt::Result {
|
2015-08-16 15:05:18 +00:00
|
|
|
try!(document(w, cx, item));
|
2014-07-04 07:51:46 +00:00
|
|
|
|
2015-01-26 21:05:07 +00:00
|
|
|
let mut indices = (0..items.len()).filter(|i| {
|
2014-11-10 00:09:17 +00:00
|
|
|
!cx.ignore_private_item(&items[*i])
|
2015-03-26 00:06:52 +00:00
|
|
|
}).collect::<Vec<usize>>();
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2014-12-03 14:57:45 +00:00
|
|
|
// the order of item types in the listing
|
|
|
|
fn reorder(ty: ItemType) -> u8 {
|
|
|
|
match ty {
|
2014-12-26 08:55:16 +00:00
|
|
|
ItemType::ExternCrate => 0,
|
|
|
|
ItemType::Import => 1,
|
|
|
|
ItemType::Primitive => 2,
|
|
|
|
ItemType::Module => 3,
|
|
|
|
ItemType::Macro => 4,
|
|
|
|
ItemType::Struct => 5,
|
|
|
|
ItemType::Enum => 6,
|
|
|
|
ItemType::Constant => 7,
|
|
|
|
ItemType::Static => 8,
|
|
|
|
ItemType::Trait => 9,
|
|
|
|
ItemType::Function => 10,
|
|
|
|
ItemType::Typedef => 12,
|
|
|
|
_ => 13 + ty as u8,
|
2014-12-03 14:57:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: usize, idx2: usize) -> Ordering {
|
2014-12-03 14:57:45 +00:00
|
|
|
let ty1 = shortty(i1);
|
|
|
|
let ty2 = shortty(i2);
|
2015-04-13 18:55:00 +00:00
|
|
|
if ty1 != ty2 {
|
|
|
|
return (reorder(ty1), idx1).cmp(&(reorder(ty2), idx2))
|
|
|
|
}
|
|
|
|
let s1 = i1.stability.as_ref().map(|s| s.level);
|
|
|
|
let s2 = i2.stability.as_ref().map(|s| s.level);
|
|
|
|
match (s1, s2) {
|
2015-10-13 03:01:31 +00:00
|
|
|
(Some(stability::Unstable), Some(stability::Stable)) => return Ordering::Greater,
|
|
|
|
(Some(stability::Stable), Some(stability::Unstable)) => return Ordering::Less,
|
2015-04-13 18:55:00 +00:00
|
|
|
_ => {}
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2015-04-13 18:55:00 +00:00
|
|
|
i1.name.cmp(&i2.name)
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 03:42:00 +00:00
|
|
|
indices.sort_by(|&i1, &i2| cmp(&items[i1], &items[i2], i1, i2));
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2014-12-20 08:09:35 +00:00
|
|
|
debug!("{:?}", indices);
|
2014-04-09 07:49:31 +00:00
|
|
|
let mut curty = None;
|
2015-01-31 17:20:46 +00:00
|
|
|
for &idx in &indices {
|
2013-09-19 05:18:38 +00:00
|
|
|
let myitem = &items[idx];
|
|
|
|
|
2014-04-09 07:49:31 +00:00
|
|
|
let myty = Some(shortty(myitem));
|
2014-12-26 08:55:16 +00:00
|
|
|
if curty == Some(ItemType::ExternCrate) && myty == Some(ItemType::Import) {
|
|
|
|
// Put `extern crate` and `use` re-exports in the same section.
|
|
|
|
curty = myty;
|
|
|
|
} else if myty != curty {
|
2014-04-09 07:49:31 +00:00
|
|
|
if curty.is_some() {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "</table>"));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
curty = myty;
|
2014-12-03 14:57:45 +00:00
|
|
|
let (short, name) = match myty.unwrap() {
|
2014-12-26 08:55:16 +00:00
|
|
|
ItemType::ExternCrate |
|
|
|
|
ItemType::Import => ("reexports", "Reexports"),
|
2014-12-03 14:57:45 +00:00
|
|
|
ItemType::Module => ("modules", "Modules"),
|
|
|
|
ItemType::Struct => ("structs", "Structs"),
|
|
|
|
ItemType::Enum => ("enums", "Enums"),
|
|
|
|
ItemType::Function => ("functions", "Functions"),
|
|
|
|
ItemType::Typedef => ("types", "Type Definitions"),
|
|
|
|
ItemType::Static => ("statics", "Statics"),
|
|
|
|
ItemType::Constant => ("constants", "Constants"),
|
|
|
|
ItemType::Trait => ("traits", "Traits"),
|
|
|
|
ItemType::Impl => ("impls", "Implementations"),
|
|
|
|
ItemType::TyMethod => ("tymethods", "Type Methods"),
|
|
|
|
ItemType::Method => ("methods", "Methods"),
|
|
|
|
ItemType::StructField => ("fields", "Struct Fields"),
|
|
|
|
ItemType::Variant => ("variants", "Variants"),
|
|
|
|
ItemType::Macro => ("macros", "Macros"),
|
|
|
|
ItemType::Primitive => ("primitives", "Primitive Types"),
|
|
|
|
ItemType::AssociatedType => ("associated-types", "Associated Types"),
|
2015-03-14 18:05:00 +00:00
|
|
|
ItemType::AssociatedConst => ("associated-consts", "Associated Constants"),
|
2014-03-04 19:24:20 +00:00
|
|
|
};
|
2015-12-03 23:48:59 +00:00
|
|
|
try!(write!(w, "<h2 id='{id}' class='section-header'>\
|
|
|
|
<a href=\"#{id}\">{name}</a></h2>\n<table>",
|
|
|
|
id = derive_id(short.to_owned()), name = name));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2014-10-07 00:41:15 +00:00
|
|
|
match myitem.inner {
|
2014-12-26 08:55:16 +00:00
|
|
|
clean::ExternCrateItem(ref name, ref src) => {
|
|
|
|
match *src {
|
|
|
|
Some(ref src) => {
|
2015-05-09 00:48:54 +00:00
|
|
|
try!(write!(w, "<tr><td><code>{}extern crate {} as {};",
|
2014-12-26 08:55:16 +00:00
|
|
|
VisSpace(myitem.visibility),
|
2015-02-02 02:53:25 +00:00
|
|
|
src,
|
|
|
|
name))
|
2013-09-24 20:56:52 +00:00
|
|
|
}
|
2014-12-26 08:55:16 +00:00
|
|
|
None => {
|
|
|
|
try!(write!(w, "<tr><td><code>{}extern crate {};",
|
2015-02-02 02:53:25 +00:00
|
|
|
VisSpace(myitem.visibility), name))
|
2013-09-24 20:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-26 08:55:16 +00:00
|
|
|
try!(write!(w, "</code></td></tr>"));
|
|
|
|
}
|
2013-09-24 20:56:52 +00:00
|
|
|
|
2014-12-26 08:55:16 +00:00
|
|
|
clean::ImportItem(ref import) => {
|
|
|
|
try!(write!(w, "<tr><td><code>{}{}</code></td></tr>",
|
|
|
|
VisSpace(myitem.visibility), *import));
|
2013-09-24 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 05:18:38 +00:00
|
|
|
_ => {
|
2013-10-01 21:31:03 +00:00
|
|
|
if myitem.name.is_none() { continue }
|
2015-08-16 15:05:18 +00:00
|
|
|
let stab_docs = if let Some(s) = short_stability(myitem, cx, false) {
|
2015-04-13 18:55:00 +00:00
|
|
|
format!("[{}]", s)
|
|
|
|
} else {
|
|
|
|
String::new()
|
|
|
|
};
|
2016-02-12 12:45:07 +00:00
|
|
|
let doc_value = myitem.doc_value().unwrap_or("");
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "
|
2015-04-13 18:55:00 +00:00
|
|
|
<tr class='{stab} module-item'>
|
|
|
|
<td><a class='{class}' href='{href}'
|
|
|
|
title='{title}'>{name}</a></td>
|
|
|
|
<td class='docblock short'>
|
|
|
|
{stab_docs} {docs}
|
|
|
|
</td>
|
2013-09-19 05:18:38 +00:00
|
|
|
</tr>
|
|
|
|
",
|
2015-04-13 18:55:00 +00:00
|
|
|
name = *myitem.name.as_ref().unwrap(),
|
|
|
|
stab_docs = stab_docs,
|
2016-02-12 12:45:07 +00:00
|
|
|
docs = shorter(Some(&Markdown(doc_value).to_string())),
|
2013-09-19 05:18:38 +00:00
|
|
|
class = shortty(myitem),
|
2015-04-13 18:55:00 +00:00
|
|
|
stab = myitem.stability_class(),
|
2013-09-19 05:18:38 +00:00
|
|
|
href = item_path(myitem),
|
2015-04-13 18:55:00 +00:00
|
|
|
title = full_path(cx, myitem)));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-04 07:51:46 +00:00
|
|
|
|
2014-01-30 19:30:21 +00:00
|
|
|
write!(w, "</table>")
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 15:05:18 +00:00
|
|
|
fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Option<String> {
|
2016-02-28 11:11:13 +00:00
|
|
|
item.stability.as_ref().and_then(|stab| {
|
2015-04-13 23:23:32 +00:00
|
|
|
let reason = if show_reason && !stab.reason.is_empty() {
|
2015-04-13 18:55:00 +00:00
|
|
|
format!(": {}", stab.reason)
|
|
|
|
} else {
|
|
|
|
String::new()
|
|
|
|
};
|
2015-04-13 23:23:32 +00:00
|
|
|
let text = if !stab.deprecated_since.is_empty() {
|
2015-04-13 18:55:00 +00:00
|
|
|
let since = if show_reason {
|
|
|
|
format!(" since {}", Escape(&stab.deprecated_since))
|
|
|
|
} else {
|
|
|
|
String::new()
|
|
|
|
};
|
|
|
|
format!("Deprecated{}{}", since, Markdown(&reason))
|
2015-10-13 03:01:31 +00:00
|
|
|
} else if stab.level == stability::Unstable {
|
2015-08-16 15:20:37 +00:00
|
|
|
let unstable_extra = if show_reason {
|
|
|
|
match (!stab.feature.is_empty(), &cx.issue_tracker_base_url, stab.issue) {
|
2016-01-11 19:38:40 +00:00
|
|
|
(true, &Some(ref tracker_url), Some(issue_no)) if issue_no > 0 =>
|
2015-08-16 21:06:57 +00:00
|
|
|
format!(" (<code>{}</code> <a href=\"{}{}\">#{}</a>)",
|
|
|
|
Escape(&stab.feature), tracker_url, issue_no, issue_no),
|
2016-01-11 19:38:40 +00:00
|
|
|
(false, &Some(ref tracker_url), Some(issue_no)) if issue_no > 0 =>
|
2015-08-16 15:20:37 +00:00
|
|
|
format!(" (<a href=\"{}{}\">#{}</a>)", Escape(&tracker_url), issue_no,
|
|
|
|
issue_no),
|
|
|
|
(true, _, _) =>
|
|
|
|
format!(" (<code>{}</code>)", Escape(&stab.feature)),
|
|
|
|
_ => String::new(),
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
String::new()
|
|
|
|
};
|
|
|
|
format!("Unstable{}{}", unstable_extra, Markdown(&reason))
|
2015-04-13 18:55:00 +00:00
|
|
|
} else {
|
|
|
|
return None
|
|
|
|
};
|
|
|
|
Some(format!("<em class='stab {}'>{}</em>",
|
|
|
|
item.stability_class(), text))
|
2016-02-28 11:11:13 +00:00
|
|
|
}).or_else(|| {
|
|
|
|
item.deprecation.as_ref().and_then(|depr| {
|
2015-12-12 20:01:27 +00:00
|
|
|
let note = if show_reason && !depr.note.is_empty() {
|
|
|
|
format!(": {}", depr.note)
|
|
|
|
} else {
|
|
|
|
String::new()
|
|
|
|
};
|
|
|
|
let since = if show_reason && !depr.since.is_empty() {
|
|
|
|
format!(" since {}", Escape(&depr.since))
|
|
|
|
} else {
|
|
|
|
String::new()
|
|
|
|
};
|
|
|
|
|
|
|
|
let text = format!("Deprecated{}{}", since, Markdown(¬e));
|
|
|
|
Some(format!("<em class='stab deprecated'>{}</em>", text))
|
2016-02-28 11:11:13 +00:00
|
|
|
})
|
|
|
|
})
|
2015-04-13 18:55:00 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 07:48:55 +00:00
|
|
|
struct Initializer<'a>(&'a str);
|
2014-12-20 08:09:35 +00:00
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
impl<'a> fmt::Display for Initializer<'a> {
|
2014-11-22 07:48:55 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let Initializer(s) = *self;
|
2015-03-24 23:53:34 +00:00
|
|
|
if s.is_empty() { return Ok(()); }
|
2014-11-22 07:48:55 +00:00
|
|
|
try!(write!(f, "<code> = </code>"));
|
2015-02-02 02:53:25 +00:00
|
|
|
write!(f, "<code>{}</code>", s)
|
2014-11-22 07:48:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-16 15:05:18 +00:00
|
|
|
fn item_constant(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
2014-11-22 07:48:55 +00:00
|
|
|
c: &clean::Constant) -> fmt::Result {
|
|
|
|
try!(write!(w, "<pre class='rust const'>{vis}const \
|
|
|
|
{name}: {typ}{init}</pre>",
|
|
|
|
vis = VisSpace(it.visibility),
|
2015-02-02 02:53:25 +00:00
|
|
|
name = it.name.as_ref().unwrap(),
|
2014-11-22 07:48:55 +00:00
|
|
|
typ = c.type_,
|
2015-02-02 02:53:25 +00:00
|
|
|
init = Initializer(&c.expr)));
|
2015-08-16 15:05:18 +00:00
|
|
|
document(w, cx, it)
|
2014-11-22 07:48:55 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 15:05:18 +00:00
|
|
|
fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
2014-11-22 07:48:55 +00:00
|
|
|
s: &clean::Static) -> fmt::Result {
|
|
|
|
try!(write!(w, "<pre class='rust static'>{vis}static {mutability}\
|
|
|
|
{name}: {typ}{init}</pre>",
|
|
|
|
vis = VisSpace(it.visibility),
|
|
|
|
mutability = MutableSpace(s.mutability),
|
2015-02-02 02:53:25 +00:00
|
|
|
name = it.name.as_ref().unwrap(),
|
2014-11-22 07:48:55 +00:00
|
|
|
typ = s.type_,
|
2015-02-02 02:53:25 +00:00
|
|
|
init = Initializer(&s.expr)));
|
2015-08-16 15:05:18 +00:00
|
|
|
document(w, cx, it)
|
2014-11-22 07:48:55 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 15:05:18 +00:00
|
|
|
fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
2014-01-30 19:30:21 +00:00
|
|
|
f: &clean::Function) -> fmt::Result {
|
2016-02-01 18:05:37 +00:00
|
|
|
let vis_constness = match get_unstable_features_setting() {
|
|
|
|
UnstableFeatures::Allow => f.constness,
|
|
|
|
_ => hir::Constness::NotConst
|
|
|
|
};
|
2015-11-19 20:08:50 +00:00
|
|
|
try!(write!(w, "<pre class='rust fn'>{vis}{constness}{unsafety}{abi}fn \
|
2014-09-25 09:01:42 +00:00
|
|
|
{name}{generics}{decl}{where_clause}</pre>",
|
2013-09-19 05:18:38 +00:00
|
|
|
vis = VisSpace(it.visibility),
|
2016-02-01 18:05:37 +00:00
|
|
|
constness = ConstnessSpace(vis_constness),
|
2014-12-09 15:36:46 +00:00
|
|
|
unsafety = UnsafetySpace(f.unsafety),
|
2015-04-07 21:22:55 +00:00
|
|
|
abi = AbiSpace(f.abi),
|
2015-02-02 02:53:25 +00:00
|
|
|
name = it.name.as_ref().unwrap(),
|
2013-09-19 05:18:38 +00:00
|
|
|
generics = f.generics,
|
2014-09-25 09:01:42 +00:00
|
|
|
where_clause = WhereClause(&f.generics),
|
2014-01-30 19:30:21 +00:00
|
|
|
decl = f.decl));
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(render_stability_since_raw(w, it.stable_since(), None));
|
2015-08-16 15:05:18 +00:00
|
|
|
document(w, cx, it)
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2014-05-21 23:41:58 +00:00
|
|
|
fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
2014-01-30 19:30:21 +00:00
|
|
|
t: &clean::Trait) -> fmt::Result {
|
2014-08-28 01:46:52 +00:00
|
|
|
let mut bounds = String::new();
|
2015-03-24 23:54:09 +00:00
|
|
|
if !t.bounds.is_empty() {
|
|
|
|
if !bounds.is_empty() {
|
2014-11-24 18:14:46 +00:00
|
|
|
bounds.push(' ');
|
|
|
|
}
|
2014-08-28 01:46:52 +00:00
|
|
|
bounds.push_str(": ");
|
|
|
|
for (i, p) in t.bounds.iter().enumerate() {
|
|
|
|
if i > 0 { bounds.push_str(" + "); }
|
2015-02-02 02:53:25 +00:00
|
|
|
bounds.push_str(&format!("{}", *p));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Output the trait definition
|
2014-12-10 00:59:20 +00:00
|
|
|
try!(write!(w, "<pre class='rust trait'>{}{}trait {}{}{}{} ",
|
2014-01-30 19:30:21 +00:00
|
|
|
VisSpace(it.visibility),
|
2014-12-10 00:59:20 +00:00
|
|
|
UnsafetySpace(t.unsafety),
|
2015-02-02 02:53:25 +00:00
|
|
|
it.name.as_ref().unwrap(),
|
2014-01-30 19:30:21 +00:00
|
|
|
t.generics,
|
2014-09-25 09:01:42 +00:00
|
|
|
bounds,
|
|
|
|
WhereClause(&t.generics)));
|
2014-11-20 19:22:09 +00:00
|
|
|
|
2016-02-28 11:23:07 +00:00
|
|
|
let types = t.items.iter().filter(|m| m.is_associated_type()).collect::<Vec<_>>();
|
|
|
|
let consts = t.items.iter().filter(|m| m.is_associated_const()).collect::<Vec<_>>();
|
|
|
|
let required = t.items.iter().filter(|m| m.is_ty_method()).collect::<Vec<_>>();
|
|
|
|
let provided = t.items.iter().filter(|m| m.is_method()).collect::<Vec<_>>();
|
2014-08-04 20:56:56 +00:00
|
|
|
|
2015-03-24 23:53:34 +00:00
|
|
|
if t.items.is_empty() {
|
2014-05-28 16:24:28 +00:00
|
|
|
try!(write!(w, "{{ }}"));
|
2013-09-19 05:18:38 +00:00
|
|
|
} else {
|
2014-05-28 16:24:28 +00:00
|
|
|
try!(write!(w, "{{\n"));
|
2015-01-31 17:20:46 +00:00
|
|
|
for t in &types {
|
2014-11-20 19:22:09 +00:00
|
|
|
try!(write!(w, " "));
|
2015-03-14 18:05:00 +00:00
|
|
|
try!(render_assoc_item(w, t, AssocItemLink::Anchor));
|
2014-11-20 19:22:09 +00:00
|
|
|
try!(write!(w, ";\n"));
|
|
|
|
}
|
2015-04-30 16:37:13 +00:00
|
|
|
if !types.is_empty() && !consts.is_empty() {
|
|
|
|
try!(w.write_str("\n"));
|
|
|
|
}
|
|
|
|
for t in &consts {
|
|
|
|
try!(write!(w, " "));
|
|
|
|
try!(render_assoc_item(w, t, AssocItemLink::Anchor));
|
|
|
|
try!(write!(w, ";\n"));
|
|
|
|
}
|
|
|
|
if !consts.is_empty() && !required.is_empty() {
|
2014-12-12 18:59:41 +00:00
|
|
|
try!(w.write_str("\n"));
|
2014-11-20 19:22:09 +00:00
|
|
|
}
|
2015-01-31 17:20:46 +00:00
|
|
|
for m in &required {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, " "));
|
2015-03-14 18:05:00 +00:00
|
|
|
try!(render_assoc_item(w, m, AssocItemLink::Anchor));
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, ";\n"));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2015-03-24 23:54:09 +00:00
|
|
|
if !required.is_empty() && !provided.is_empty() {
|
2014-12-12 18:59:41 +00:00
|
|
|
try!(w.write_str("\n"));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2015-01-31 17:20:46 +00:00
|
|
|
for m in &provided {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, " "));
|
2015-03-14 18:05:00 +00:00
|
|
|
try!(render_assoc_item(w, m, AssocItemLink::Anchor));
|
2014-05-28 16:24:28 +00:00
|
|
|
try!(write!(w, " {{ ... }}\n"));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-05-28 16:24:28 +00:00
|
|
|
try!(write!(w, "}}"));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "</pre>"));
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
|
|
// Trait documentation
|
2015-08-16 15:05:18 +00:00
|
|
|
try!(document(w, cx, it));
|
2014-01-30 19:30:21 +00:00
|
|
|
|
2016-02-10 02:15:29 +00:00
|
|
|
fn trait_item(w: &mut fmt::Formatter, cx: &Context, m: &clean::Item, t: &clean::Item)
|
2014-08-04 20:56:56 +00:00
|
|
|
-> fmt::Result {
|
2015-12-02 22:49:18 +00:00
|
|
|
let name = m.name.as_ref().unwrap();
|
2015-12-03 23:48:59 +00:00
|
|
|
let id = derive_id(format!("{}.{}", shortty(m), name));
|
|
|
|
try!(write!(w, "<h3 id='{id}' class='method stab {stab}'><code>",
|
2015-12-02 22:49:18 +00:00
|
|
|
id = id,
|
2015-12-03 23:48:59 +00:00
|
|
|
stab = m.stability_class()));
|
2015-03-14 18:05:00 +00:00
|
|
|
try!(render_assoc_item(w, m, AssocItemLink::Anchor));
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(write!(w, "</code>"));
|
|
|
|
try!(render_stability_since(w, m, t));
|
|
|
|
try!(write!(w, "</h3>"));
|
2015-08-16 15:05:18 +00:00
|
|
|
try!(document(w, cx, m));
|
2014-01-30 19:30:21 +00:00
|
|
|
Ok(())
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2015-03-24 23:54:09 +00:00
|
|
|
if !types.is_empty() {
|
2014-11-20 19:22:09 +00:00
|
|
|
try!(write!(w, "
|
|
|
|
<h2 id='associated-types'>Associated Types</h2>
|
|
|
|
<div class='methods'>
|
|
|
|
"));
|
2015-01-31 17:20:46 +00:00
|
|
|
for t in &types {
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(trait_item(w, cx, *t, it));
|
2014-11-20 19:22:09 +00:00
|
|
|
}
|
|
|
|
try!(write!(w, "</div>"));
|
|
|
|
}
|
|
|
|
|
2015-05-08 22:16:20 +00:00
|
|
|
if !consts.is_empty() {
|
|
|
|
try!(write!(w, "
|
|
|
|
<h2 id='associated-const'>Associated Constants</h2>
|
|
|
|
<div class='methods'>
|
|
|
|
"));
|
|
|
|
for t in &consts {
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(trait_item(w, cx, *t, it));
|
2015-05-08 22:16:20 +00:00
|
|
|
}
|
|
|
|
try!(write!(w, "</div>"));
|
|
|
|
}
|
|
|
|
|
2013-09-19 05:18:38 +00:00
|
|
|
// Output the documentation for each function individually
|
2015-03-24 23:54:09 +00:00
|
|
|
if !required.is_empty() {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "
|
2013-09-19 05:18:38 +00:00
|
|
|
<h2 id='required-methods'>Required Methods</h2>
|
|
|
|
<div class='methods'>
|
2014-01-30 19:30:21 +00:00
|
|
|
"));
|
2015-01-31 17:20:46 +00:00
|
|
|
for m in &required {
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(trait_item(w, cx, *m, it));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "</div>"));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2015-03-24 23:54:09 +00:00
|
|
|
if !provided.is_empty() {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "
|
2013-09-19 05:18:38 +00:00
|
|
|
<h2 id='provided-methods'>Provided Methods</h2>
|
|
|
|
<div class='methods'>
|
2014-01-30 19:30:21 +00:00
|
|
|
"));
|
2015-01-31 17:20:46 +00:00
|
|
|
for m in &provided {
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(trait_item(w, cx, *m, it));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "</div>"));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 02:21:52 +00:00
|
|
|
// If there are methods directly on this trait object, render them here.
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All));
|
2015-04-07 02:21:52 +00:00
|
|
|
|
2014-11-14 22:20:57 +00:00
|
|
|
let cache = cache();
|
2014-05-28 00:52:40 +00:00
|
|
|
try!(write!(w, "
|
|
|
|
<h2 id='implementors'>Implementors</h2>
|
|
|
|
<ul class='item-list' id='implementors-list'>
|
|
|
|
"));
|
2014-11-06 17:25:16 +00:00
|
|
|
match cache.implementors.get(&it.def_id) {
|
2014-04-29 03:36:08 +00:00
|
|
|
Some(implementors) => {
|
2015-01-31 17:20:46 +00:00
|
|
|
for i in implementors {
|
2015-07-18 06:02:57 +00:00
|
|
|
try!(writeln!(w, "<li><code>{}</code></li>", i.impl_));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2013-12-06 02:19:06 +00:00
|
|
|
}
|
2014-04-29 03:36:08 +00:00
|
|
|
None => {}
|
|
|
|
}
|
2014-05-28 00:52:40 +00:00
|
|
|
try!(write!(w, "</ul>"));
|
|
|
|
try!(write!(w, r#"<script type="text/javascript" async
|
2014-05-29 16:58:09 +00:00
|
|
|
src="{root_path}/implementors/{path}/{ty}.{name}.js">
|
|
|
|
</script>"#,
|
2015-07-10 12:19:21 +00:00
|
|
|
root_path = vec![".."; cx.current.len()].join("/"),
|
2015-08-16 10:32:28 +00:00
|
|
|
path = if it.def_id.is_local() {
|
2015-07-10 12:19:21 +00:00
|
|
|
cx.current.join("/")
|
2014-05-28 00:52:40 +00:00
|
|
|
} else {
|
2015-03-22 01:15:47 +00:00
|
|
|
let path = &cache.external_paths[&it.def_id];
|
2015-07-10 12:19:21 +00:00
|
|
|
path[..path.len() - 1].join("/")
|
2014-05-28 00:52:40 +00:00
|
|
|
},
|
|
|
|
ty = shortty(it).to_static_str(),
|
2014-10-15 06:05:01 +00:00
|
|
|
name = *it.name.as_ref().unwrap()));
|
2014-04-29 03:36:08 +00:00
|
|
|
Ok(())
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 01:35:25 +00:00
|
|
|
fn assoc_const(w: &mut fmt::Formatter, it: &clean::Item,
|
2015-04-30 16:37:13 +00:00
|
|
|
ty: &clean::Type, default: Option<&String>)
|
2015-03-16 01:35:25 +00:00
|
|
|
-> fmt::Result {
|
|
|
|
try!(write!(w, "const {}", it.name.as_ref().unwrap()));
|
|
|
|
try!(write!(w, ": {}", ty));
|
2015-04-30 16:37:13 +00:00
|
|
|
if let Some(default) = default {
|
2015-03-16 01:35:25 +00:00
|
|
|
try!(write!(w, " = {}", default));
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2015-01-02 13:26:55 +00:00
|
|
|
fn assoc_type(w: &mut fmt::Formatter, it: &clean::Item,
|
2015-03-10 10:28:44 +00:00
|
|
|
bounds: &Vec<clean::TyParamBound>,
|
|
|
|
default: &Option<clean::Type>)
|
|
|
|
-> fmt::Result {
|
2015-01-02 13:26:55 +00:00
|
|
|
try!(write!(w, "type {}", it.name.as_ref().unwrap()));
|
2015-03-24 23:54:09 +00:00
|
|
|
if !bounds.is_empty() {
|
2015-03-10 10:28:44 +00:00
|
|
|
try!(write!(w, ": {}", TyParamBounds(bounds)))
|
2015-01-02 13:26:55 +00:00
|
|
|
}
|
2015-03-10 10:28:44 +00:00
|
|
|
if let Some(ref default) = *default {
|
2015-01-02 13:26:55 +00:00
|
|
|
try!(write!(w, " = {}", default));
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2016-02-10 02:15:29 +00:00
|
|
|
fn render_stability_since_raw<'a>(w: &mut fmt::Formatter,
|
|
|
|
ver: Option<&'a str>,
|
|
|
|
containing_ver: Option<&'a str>) -> fmt::Result {
|
2016-02-28 11:11:13 +00:00
|
|
|
if let Some(v) = ver {
|
|
|
|
if containing_ver != ver && v.len() > 0 {
|
|
|
|
try!(write!(w, "<span class=\"since\">{}</span>",
|
|
|
|
v))
|
2016-02-10 02:15:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn render_stability_since(w: &mut fmt::Formatter,
|
|
|
|
item: &clean::Item,
|
|
|
|
containing_item: &clean::Item) -> fmt::Result {
|
|
|
|
render_stability_since_raw(w, item.stable_since(), containing_item.stable_since())
|
|
|
|
}
|
|
|
|
|
2015-03-14 18:05:00 +00:00
|
|
|
fn render_assoc_item(w: &mut fmt::Formatter, meth: &clean::Item,
|
|
|
|
link: AssocItemLink) -> fmt::Result {
|
2015-02-25 20:05:07 +00:00
|
|
|
fn method(w: &mut fmt::Formatter,
|
|
|
|
it: &clean::Item,
|
2015-07-31 07:04:06 +00:00
|
|
|
unsafety: hir::Unsafety,
|
|
|
|
constness: hir::Constness,
|
2015-02-25 20:05:07 +00:00
|
|
|
abi: abi::Abi,
|
|
|
|
g: &clean::Generics,
|
|
|
|
selfty: &clean::SelfTy,
|
|
|
|
d: &clean::FnDecl,
|
|
|
|
link: AssocItemLink)
|
|
|
|
-> fmt::Result {
|
2015-02-06 08:51:38 +00:00
|
|
|
use syntax::abi::Abi;
|
|
|
|
|
2015-04-07 00:56:35 +00:00
|
|
|
let name = it.name.as_ref().unwrap();
|
|
|
|
let anchor = format!("#{}.{}", shortty(it), name);
|
|
|
|
let href = match link {
|
2015-03-14 18:05:00 +00:00
|
|
|
AssocItemLink::Anchor => anchor,
|
|
|
|
AssocItemLink::GotoSource(did) => {
|
2015-04-07 00:56:35 +00:00
|
|
|
href(did).map(|p| format!("{}{}", p.0, anchor)).unwrap_or(anchor)
|
|
|
|
}
|
|
|
|
};
|
2016-02-01 18:05:37 +00:00
|
|
|
let vis_constness = match get_unstable_features_setting() {
|
|
|
|
UnstableFeatures::Allow => constness,
|
|
|
|
_ => hir::Constness::NotConst
|
|
|
|
};
|
2015-02-25 20:05:07 +00:00
|
|
|
write!(w, "{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
|
2014-09-25 09:01:42 +00:00
|
|
|
{generics}{decl}{where_clause}",
|
2016-02-01 18:05:37 +00:00
|
|
|
ConstnessSpace(vis_constness),
|
2015-11-19 20:08:50 +00:00
|
|
|
UnsafetySpace(unsafety),
|
2015-02-06 08:51:38 +00:00
|
|
|
match abi {
|
|
|
|
Abi::Rust => String::new(),
|
|
|
|
a => format!("extern {} ", a.to_string())
|
|
|
|
},
|
2015-04-07 00:56:35 +00:00
|
|
|
href = href,
|
|
|
|
name = name,
|
2013-09-19 05:18:38 +00:00
|
|
|
generics = *g,
|
2014-09-25 09:01:42 +00:00
|
|
|
decl = Method(selfty, d),
|
|
|
|
where_clause = WhereClause(g))
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
match meth.inner {
|
|
|
|
clean::TyMethodItem(ref m) => {
|
2015-07-31 07:04:06 +00:00
|
|
|
method(w, meth, m.unsafety, hir::Constness::NotConst,
|
2015-02-25 20:05:07 +00:00
|
|
|
m.abi, &m.generics, &m.self_, &m.decl, link)
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
clean::MethodItem(ref m) => {
|
2015-02-25 20:05:07 +00:00
|
|
|
method(w, meth, m.unsafety, m.constness,
|
|
|
|
m.abi, &m.generics, &m.self_, &m.decl,
|
2015-04-07 00:56:35 +00:00
|
|
|
link)
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2015-03-16 01:35:25 +00:00
|
|
|
clean::AssociatedConstItem(ref ty, ref default) => {
|
2015-04-30 16:37:13 +00:00
|
|
|
assoc_const(w, meth, ty, default.as_ref())
|
2015-03-16 01:35:25 +00:00
|
|
|
}
|
2015-03-10 10:28:44 +00:00
|
|
|
clean::AssociatedTypeItem(ref bounds, ref default) => {
|
|
|
|
assoc_type(w, meth, bounds, default)
|
2014-11-20 19:22:09 +00:00
|
|
|
}
|
2015-03-14 18:05:00 +00:00
|
|
|
_ => panic!("render_assoc_item called on non-associated-item")
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-16 15:05:18 +00:00
|
|
|
fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
2014-01-30 19:30:21 +00:00
|
|
|
s: &clean::Struct) -> fmt::Result {
|
2014-02-20 09:14:51 +00:00
|
|
|
try!(write!(w, "<pre class='rust struct'>"));
|
2015-02-12 15:47:03 +00:00
|
|
|
try!(render_attributes(w, it));
|
2014-03-05 23:28:08 +00:00
|
|
|
try!(render_struct(w,
|
|
|
|
it,
|
|
|
|
Some(&s.generics),
|
|
|
|
s.struct_type,
|
2015-02-02 02:53:25 +00:00
|
|
|
&s.fields,
|
2014-03-05 23:28:08 +00:00
|
|
|
"",
|
|
|
|
true));
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "</pre>"));
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(render_stability_since_raw(w, it.stable_since(), None));
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2015-08-16 15:05:18 +00:00
|
|
|
try!(document(w, cx, it));
|
2014-04-20 05:24:52 +00:00
|
|
|
let mut fields = s.fields.iter().filter(|f| {
|
|
|
|
match f.inner {
|
|
|
|
clean::StructFieldItem(clean::HiddenStructField) => false,
|
|
|
|
clean::StructFieldItem(clean::TypedStructField(..)) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}).peekable();
|
2014-11-29 21:41:21 +00:00
|
|
|
if let doctree::Plain = s.struct_type {
|
|
|
|
if fields.peek().is_some() {
|
|
|
|
try!(write!(w, "<h2 class='fields'>Fields</h2>\n<table>"));
|
|
|
|
for field in fields {
|
2015-04-13 18:55:00 +00:00
|
|
|
try!(write!(w, "<tr class='stab {stab}'>
|
|
|
|
<td id='structfield.{name}'>\
|
|
|
|
<code>{name}</code></td><td>",
|
|
|
|
stab = field.stability_class(),
|
2015-02-02 02:53:25 +00:00
|
|
|
name = field.name.as_ref().unwrap()));
|
2015-08-16 15:05:18 +00:00
|
|
|
try!(document(w, cx, field));
|
2014-11-29 21:41:21 +00:00
|
|
|
try!(write!(w, "</td></tr>"));
|
2013-09-30 23:31:35 +00:00
|
|
|
}
|
2014-11-29 21:41:21 +00:00
|
|
|
try!(write!(w, "</table>"));
|
2013-09-30 23:31:35 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-10 02:15:29 +00:00
|
|
|
render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 15:05:18 +00:00
|
|
|
fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
2014-05-10 21:05:06 +00:00
|
|
|
e: &clean::Enum) -> fmt::Result {
|
2015-02-12 15:47:03 +00:00
|
|
|
try!(write!(w, "<pre class='rust enum'>"));
|
|
|
|
try!(render_attributes(w, it));
|
|
|
|
try!(write!(w, "{}enum {}{}{}",
|
2014-01-30 19:30:21 +00:00
|
|
|
VisSpace(it.visibility),
|
2015-02-02 02:53:25 +00:00
|
|
|
it.name.as_ref().unwrap(),
|
2014-09-25 09:01:42 +00:00
|
|
|
e.generics,
|
|
|
|
WhereClause(&e.generics)));
|
2015-03-24 23:53:34 +00:00
|
|
|
if e.variants.is_empty() && !e.variants_stripped {
|
2014-05-28 16:24:28 +00:00
|
|
|
try!(write!(w, " {{}}"));
|
2013-09-19 05:18:38 +00:00
|
|
|
} else {
|
2014-05-28 16:24:28 +00:00
|
|
|
try!(write!(w, " {{\n"));
|
2015-01-31 17:20:46 +00:00
|
|
|
for v in &e.variants {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, " "));
|
2015-02-02 02:53:25 +00:00
|
|
|
let name = v.name.as_ref().unwrap();
|
2013-09-19 05:18:38 +00:00
|
|
|
match v.inner {
|
|
|
|
clean::VariantItem(ref var) => {
|
|
|
|
match var.kind {
|
2014-02-19 18:07:49 +00:00
|
|
|
clean::CLikeVariant => try!(write!(w, "{}", name)),
|
2013-09-19 05:18:38 +00:00
|
|
|
clean::TupleVariant(ref tys) => {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "{}(", name));
|
2013-09-19 05:18:38 +00:00
|
|
|
for (i, ty) in tys.iter().enumerate() {
|
2014-01-30 19:30:21 +00:00
|
|
|
if i > 0 {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, ", "))
|
2014-01-30 19:30:21 +00:00
|
|
|
}
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "{}", *ty));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, ")"));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
clean::StructVariant(ref s) => {
|
2014-03-05 23:28:08 +00:00
|
|
|
try!(render_struct(w,
|
|
|
|
v,
|
|
|
|
None,
|
|
|
|
s.struct_type,
|
2015-02-02 02:53:25 +00:00
|
|
|
&s.fields,
|
2014-03-05 23:28:08 +00:00
|
|
|
" ",
|
|
|
|
false));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => unreachable!()
|
|
|
|
}
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, ",\n"));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2013-10-14 03:37:43 +00:00
|
|
|
|
|
|
|
if e.variants_stripped {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, " // some variants omitted\n"));
|
2013-10-14 03:37:43 +00:00
|
|
|
}
|
2014-05-28 16:24:28 +00:00
|
|
|
try!(write!(w, "}}"));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "</pre>"));
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(render_stability_since_raw(w, it.stable_since(), None));
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2015-08-16 15:05:18 +00:00
|
|
|
try!(document(w, cx, it));
|
2015-03-24 23:54:09 +00:00
|
|
|
if !e.variants.is_empty() {
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(write!(w, "<h2 class='variants'>Variants</h2>\n<table class='variants_table'>"));
|
2015-01-31 17:20:46 +00:00
|
|
|
for variant in &e.variants {
|
2015-04-13 18:55:00 +00:00
|
|
|
try!(write!(w, "<tr><td id='variant.{name}'><code>{name}</code></td><td>",
|
2015-02-02 02:53:25 +00:00
|
|
|
name = variant.name.as_ref().unwrap()));
|
2015-08-16 15:05:18 +00:00
|
|
|
try!(document(w, cx, variant));
|
2016-02-28 11:11:13 +00:00
|
|
|
|
|
|
|
use clean::{Variant, StructVariant};
|
|
|
|
if let clean::VariantItem( Variant { kind: StructVariant(ref s) } ) = variant.inner {
|
|
|
|
let fields = s.fields.iter().filter(|f| {
|
|
|
|
match f.inner {
|
|
|
|
clean::StructFieldItem(clean::TypedStructField(..)) => true,
|
|
|
|
_ => false,
|
2013-10-19 05:00:08 +00:00
|
|
|
}
|
2016-02-28 11:11:13 +00:00
|
|
|
});
|
|
|
|
try!(write!(w, "<h3 class='fields'>Fields</h3>\n
|
|
|
|
<table>"));
|
|
|
|
for field in fields {
|
|
|
|
try!(write!(w, "<tr><td \
|
|
|
|
id='variant.{v}.field.{f}'>\
|
|
|
|
<code>{f}</code></td><td>",
|
|
|
|
v = variant.name.as_ref().unwrap(),
|
|
|
|
f = field.name.as_ref().unwrap()));
|
|
|
|
try!(document(w, cx, field));
|
|
|
|
try!(write!(w, "</td></tr>"));
|
2013-10-19 05:00:08 +00:00
|
|
|
}
|
2016-02-28 11:11:13 +00:00
|
|
|
try!(write!(w, "</table>"));
|
2013-10-19 05:00:08 +00:00
|
|
|
}
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(write!(w, "</td><td>"));
|
|
|
|
try!(render_stability_since(w, variant, it));
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "</td></tr>"));
|
2013-09-30 23:31:35 +00:00
|
|
|
}
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "</table>"));
|
2013-09-30 23:31:35 +00:00
|
|
|
}
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All));
|
2014-01-30 19:30:21 +00:00
|
|
|
Ok(())
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 15:47:03 +00:00
|
|
|
fn render_attributes(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
|
|
|
|
for attr in &it.attrs {
|
|
|
|
match *attr {
|
|
|
|
clean::Word(ref s) if *s == "must_use" => {
|
|
|
|
try!(write!(w, "#[{}]\n", s));
|
|
|
|
}
|
|
|
|
clean::NameValue(ref k, ref v) if *k == "must_use" => {
|
|
|
|
try!(write!(w, "#[{} = \"{}\"]\n", k, v));
|
|
|
|
}
|
|
|
|
_ => ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2014-05-10 21:05:06 +00:00
|
|
|
fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
|
2013-09-19 05:18:38 +00:00
|
|
|
g: Option<&clean::Generics>,
|
|
|
|
ty: doctree::StructType,
|
|
|
|
fields: &[clean::Item],
|
2013-09-30 18:44:25 +00:00
|
|
|
tab: &str,
|
2014-01-30 19:30:21 +00:00
|
|
|
structhead: bool) -> fmt::Result {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "{}{}{}",
|
2014-01-30 19:30:21 +00:00
|
|
|
VisSpace(it.visibility),
|
|
|
|
if structhead {"struct "} else {""},
|
2015-02-02 02:53:25 +00:00
|
|
|
it.name.as_ref().unwrap()));
|
2016-02-28 11:11:13 +00:00
|
|
|
if let Some(g) = g {
|
|
|
|
try!(write!(w, "{}{}", *g, WhereClause(g)))
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
match ty {
|
|
|
|
doctree::Plain => {
|
2014-05-28 16:24:28 +00:00
|
|
|
try!(write!(w, " {{\n{}", tab));
|
2014-04-20 05:24:52 +00:00
|
|
|
let mut fields_stripped = false;
|
2015-01-31 17:20:46 +00:00
|
|
|
for field in fields {
|
2013-09-19 05:18:38 +00:00
|
|
|
match field.inner {
|
2014-04-20 05:24:52 +00:00
|
|
|
clean::StructFieldItem(clean::HiddenStructField) => {
|
|
|
|
fields_stripped = true;
|
|
|
|
}
|
|
|
|
clean::StructFieldItem(clean::TypedStructField(ref ty)) => {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, " {}{}: {},\n{}",
|
2014-01-30 19:30:21 +00:00
|
|
|
VisSpace(field.visibility),
|
2015-02-02 02:53:25 +00:00
|
|
|
field.name.as_ref().unwrap(),
|
2014-04-20 05:24:52 +00:00
|
|
|
*ty,
|
2014-01-30 19:30:21 +00:00
|
|
|
tab));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-04-20 05:24:52 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2013-10-14 03:37:43 +00:00
|
|
|
|
|
|
|
if fields_stripped {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, " // some fields omitted\n{}", tab));
|
2013-10-14 03:37:43 +00:00
|
|
|
}
|
2014-05-28 16:24:28 +00:00
|
|
|
try!(write!(w, "}}"));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
doctree::Tuple | doctree::Newtype => {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "("));
|
2013-09-19 05:18:38 +00:00
|
|
|
for (i, field) in fields.iter().enumerate() {
|
2014-01-30 19:30:21 +00:00
|
|
|
if i > 0 {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, ", "));
|
2014-01-30 19:30:21 +00:00
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
match field.inner {
|
2014-04-20 05:24:52 +00:00
|
|
|
clean::StructFieldItem(clean::HiddenStructField) => {
|
|
|
|
try!(write!(w, "_"))
|
|
|
|
}
|
|
|
|
clean::StructFieldItem(clean::TypedStructField(ref ty)) => {
|
|
|
|
try!(write!(w, "{}{}", VisSpace(field.visibility), *ty))
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
_ => unreachable!()
|
|
|
|
}
|
|
|
|
}
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, ");"));
|
2014-01-30 19:30:21 +00:00
|
|
|
}
|
|
|
|
doctree::Unit => {
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, ";"));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-30 19:30:21 +00:00
|
|
|
Ok(())
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 00:56:35 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2015-03-14 18:05:00 +00:00
|
|
|
enum AssocItemLink {
|
2015-04-07 00:56:35 +00:00
|
|
|
Anchor,
|
2015-08-16 10:32:28 +00:00
|
|
|
GotoSource(DefId),
|
2015-04-07 00:56:35 +00:00
|
|
|
}
|
|
|
|
|
2015-03-14 18:05:00 +00:00
|
|
|
enum AssocItemRender<'a> {
|
2015-04-13 23:23:32 +00:00
|
|
|
All,
|
|
|
|
DerefFor { trait_: &'a clean::Type, type_: &'a clean::Type },
|
|
|
|
}
|
|
|
|
|
2015-03-14 18:05:00 +00:00
|
|
|
fn render_assoc_items(w: &mut fmt::Formatter,
|
2015-08-16 15:05:18 +00:00
|
|
|
cx: &Context,
|
2016-02-10 02:15:29 +00:00
|
|
|
containing_item: &clean::Item,
|
2015-08-16 10:32:28 +00:00
|
|
|
it: DefId,
|
2015-03-14 18:05:00 +00:00
|
|
|
what: AssocItemRender) -> fmt::Result {
|
2015-04-13 23:23:32 +00:00
|
|
|
let c = cache();
|
|
|
|
let v = match c.impls.get(&it) {
|
|
|
|
Some(v) => v,
|
2015-04-07 02:21:52 +00:00
|
|
|
None => return Ok(()),
|
|
|
|
};
|
2015-04-13 23:23:32 +00:00
|
|
|
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| {
|
|
|
|
i.impl_.trait_.is_none()
|
|
|
|
});
|
2015-03-24 23:54:09 +00:00
|
|
|
if !non_trait.is_empty() {
|
2015-04-13 23:23:32 +00:00
|
|
|
let render_header = match what {
|
2015-03-14 18:05:00 +00:00
|
|
|
AssocItemRender::All => {
|
2015-04-13 23:23:32 +00:00
|
|
|
try!(write!(w, "<h2 id='methods'>Methods</h2>"));
|
|
|
|
true
|
|
|
|
}
|
2015-03-14 18:05:00 +00:00
|
|
|
AssocItemRender::DerefFor { trait_, type_ } => {
|
2015-04-13 23:23:32 +00:00
|
|
|
try!(write!(w, "<h2 id='deref-methods'>Methods from \
|
|
|
|
{}<Target={}></h2>", trait_, type_));
|
|
|
|
false
|
|
|
|
}
|
|
|
|
};
|
2015-04-07 02:21:52 +00:00
|
|
|
for i in &non_trait {
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(render_impl(w, cx, i, AssocItemLink::Anchor, render_header,
|
|
|
|
containing_item.stable_since()));
|
2015-04-07 02:21:52 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-14 18:05:00 +00:00
|
|
|
if let AssocItemRender::DerefFor { .. } = what {
|
2016-02-28 11:11:13 +00:00
|
|
|
return Ok(());
|
2015-04-13 23:23:32 +00:00
|
|
|
}
|
2015-03-24 23:54:09 +00:00
|
|
|
if !traits.is_empty() {
|
2015-04-13 23:23:32 +00:00
|
|
|
let deref_impl = traits.iter().find(|t| {
|
|
|
|
match *t.impl_.trait_.as_ref().unwrap() {
|
|
|
|
clean::ResolvedPath { did, .. } => {
|
|
|
|
Some(did) == c.deref_trait_did
|
|
|
|
}
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if let Some(impl_) = deref_impl {
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(render_deref_methods(w, cx, impl_, containing_item));
|
2015-04-13 23:23:32 +00:00
|
|
|
}
|
2015-04-07 02:21:52 +00:00
|
|
|
try!(write!(w, "<h2 id='implementations'>Trait \
|
|
|
|
Implementations</h2>"));
|
2015-06-03 10:38:42 +00:00
|
|
|
let (derived, manual): (Vec<_>, Vec<&Impl>) = traits.iter().partition(|i| {
|
2015-04-13 23:23:32 +00:00
|
|
|
i.impl_.derived
|
|
|
|
});
|
2015-04-07 02:21:52 +00:00
|
|
|
for i in &manual {
|
|
|
|
let did = i.trait_did().unwrap();
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(render_impl(w, cx, i, AssocItemLink::GotoSource(did), true,
|
|
|
|
containing_item.stable_since()));
|
2015-04-07 02:21:52 +00:00
|
|
|
}
|
2015-03-24 23:54:09 +00:00
|
|
|
if !derived.is_empty() {
|
2015-04-07 02:21:52 +00:00
|
|
|
try!(write!(w, "<h3 id='derived_implementations'>\
|
|
|
|
Derived Implementations \
|
|
|
|
</h3>"));
|
|
|
|
for i in &derived {
|
|
|
|
let did = i.trait_did().unwrap();
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(render_impl(w, cx, i, AssocItemLink::GotoSource(did), true,
|
|
|
|
containing_item.stable_since()));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2013-12-06 02:19:06 +00:00
|
|
|
}
|
2014-04-29 03:36:08 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2016-02-10 02:15:29 +00:00
|
|
|
fn render_deref_methods(w: &mut fmt::Formatter, cx: &Context, impl_: &Impl,
|
|
|
|
container_item: &clean::Item) -> fmt::Result {
|
2015-04-13 23:23:32 +00:00
|
|
|
let deref_type = impl_.impl_.trait_.as_ref().unwrap();
|
|
|
|
let target = impl_.impl_.items.iter().filter_map(|item| {
|
|
|
|
match item.inner {
|
2015-05-21 12:17:37 +00:00
|
|
|
clean::TypedefItem(ref t, true) => Some(&t.type_),
|
2015-04-13 23:23:32 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
2015-05-21 12:17:37 +00:00
|
|
|
}).next().expect("Expected associated type binding");
|
2015-03-14 18:05:00 +00:00
|
|
|
let what = AssocItemRender::DerefFor { trait_: deref_type, type_: target };
|
2015-04-13 23:23:32 +00:00
|
|
|
match *target {
|
2016-02-10 02:15:29 +00:00
|
|
|
clean::ResolvedPath { did, .. } => render_assoc_items(w, cx, container_item, did, what),
|
2015-04-13 23:23:32 +00:00
|
|
|
_ => {
|
|
|
|
if let Some(prim) = target.primitive_type() {
|
|
|
|
if let Some(c) = cache().primitive_locations.get(&prim) {
|
2015-09-17 18:29:59 +00:00
|
|
|
let did = DefId { krate: *c, index: prim.to_def_index() };
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(render_assoc_items(w, cx, container_item, did, what));
|
2015-04-13 23:23:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
2014-05-03 09:08:58 +00:00
|
|
|
}
|
2015-04-13 23:23:32 +00:00
|
|
|
}
|
|
|
|
|
2015-04-26 19:03:38 +00:00
|
|
|
// Render_header is false when we are rendering a `Deref` impl and true
|
|
|
|
// otherwise. If render_header is false, we will avoid rendering static
|
|
|
|
// methods, since they are not accessible for the type implementing `Deref`
|
2015-08-16 15:05:18 +00:00
|
|
|
fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLink,
|
2016-02-10 02:15:29 +00:00
|
|
|
render_header: bool, outer_version: Option<&str>) -> fmt::Result {
|
2015-04-13 23:23:32 +00:00
|
|
|
if render_header {
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(write!(w, "<h3 class='impl'><code>{}</code>", i.impl_));
|
|
|
|
let since = i.stability.as_ref().map(|s| &s.since[..]);
|
|
|
|
try!(render_stability_since_raw(w, since, outer_version));
|
|
|
|
try!(write!(w, "</h3>"));
|
2015-04-13 23:23:32 +00:00
|
|
|
if let Some(ref dox) = i.dox {
|
|
|
|
try!(write!(w, "<div class='docblock'>{}</div>", Markdown(dox)));
|
|
|
|
}
|
2013-10-01 00:04:14 +00:00
|
|
|
}
|
2013-10-21 18:33:04 +00:00
|
|
|
|
2015-08-16 15:05:18 +00:00
|
|
|
fn doctraititem(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item,
|
2016-02-10 02:15:29 +00:00
|
|
|
link: AssocItemLink, render_static: bool,
|
|
|
|
outer_version: Option<&str>) -> fmt::Result {
|
2015-12-02 22:49:18 +00:00
|
|
|
let name = item.name.as_ref().unwrap();
|
2016-02-28 11:11:13 +00:00
|
|
|
|
|
|
|
let is_static = match item.inner {
|
|
|
|
clean::MethodItem(ref method) => method.self_ == SelfTy::SelfStatic,
|
|
|
|
clean::TyMethodItem(ref method) => method.self_ == SelfTy::SelfStatic,
|
|
|
|
_ => false
|
|
|
|
};
|
|
|
|
|
2014-11-20 19:22:09 +00:00
|
|
|
match item.inner {
|
|
|
|
clean::MethodItem(..) | clean::TyMethodItem(..) => {
|
2015-04-26 19:03:38 +00:00
|
|
|
// Only render when the method is not static or we allow static methods
|
2016-02-28 11:11:13 +00:00
|
|
|
if !is_static || render_static {
|
2015-12-03 23:48:59 +00:00
|
|
|
let id = derive_id(format!("method.{}", name));
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(write!(w, "<h4 id='{}' class='{}'>", id, shortty(item)));
|
|
|
|
try!(render_stability_since_raw(w, item.stable_since(), outer_version));
|
|
|
|
try!(write!(w, "<code>"));
|
|
|
|
try!(render_assoc_item(w, item, link));
|
2015-04-26 19:03:38 +00:00
|
|
|
try!(write!(w, "</code></h4>\n"));
|
|
|
|
}
|
2014-11-20 19:22:09 +00:00
|
|
|
}
|
2015-05-21 12:17:37 +00:00
|
|
|
clean::TypedefItem(ref tydef, _) => {
|
2016-02-12 08:43:33 +00:00
|
|
|
let id = derive_id(format!("associatedtype.{}", name));
|
2015-12-03 23:48:59 +00:00
|
|
|
try!(write!(w, "<h4 id='{}' class='{}'><code>", id, shortty(item)));
|
2014-11-20 19:22:09 +00:00
|
|
|
try!(write!(w, "type {} = {}", name, tydef.type_));
|
|
|
|
try!(write!(w, "</code></h4>\n"));
|
|
|
|
}
|
2015-03-16 01:35:25 +00:00
|
|
|
clean::AssociatedConstItem(ref ty, ref default) => {
|
2016-02-12 08:43:33 +00:00
|
|
|
let id = derive_id(format!("associatedconstant.{}", name));
|
2015-12-03 23:48:59 +00:00
|
|
|
try!(write!(w, "<h4 id='{}' class='{}'><code>", id, shortty(item)));
|
2015-04-30 16:37:13 +00:00
|
|
|
try!(assoc_const(w, item, ty, default.as_ref()));
|
|
|
|
try!(write!(w, "</code></h4>\n"));
|
|
|
|
}
|
|
|
|
clean::ConstantItem(ref c) => {
|
2016-02-12 08:43:33 +00:00
|
|
|
let id = derive_id(format!("associatedconstant.{}", name));
|
2015-12-03 23:48:59 +00:00
|
|
|
try!(write!(w, "<h4 id='{}' class='{}'><code>", id, shortty(item)));
|
2015-04-30 16:37:13 +00:00
|
|
|
try!(assoc_const(w, item, &c.type_, Some(&c.expr)));
|
2015-03-16 01:35:25 +00:00
|
|
|
try!(write!(w, "</code></h4>\n"));
|
|
|
|
}
|
2015-03-10 10:28:44 +00:00
|
|
|
clean::AssociatedTypeItem(ref bounds, ref default) => {
|
2016-02-12 08:43:33 +00:00
|
|
|
let id = derive_id(format!("associatedtype.{}", name));
|
2015-12-03 23:48:59 +00:00
|
|
|
try!(write!(w, "<h4 id='{}' class='{}'><code>", id, shortty(item)));
|
2015-03-10 10:28:44 +00:00
|
|
|
try!(assoc_type(w, item, bounds, default));
|
2015-01-02 13:26:55 +00:00
|
|
|
try!(write!(w, "</code></h4>\n"));
|
|
|
|
}
|
2014-12-20 08:09:35 +00:00
|
|
|
_ => panic!("can't make docs for trait item with name {:?}", item.name)
|
2014-11-20 19:22:09 +00:00
|
|
|
}
|
2015-04-26 19:03:38 +00:00
|
|
|
|
2016-02-28 11:11:13 +00:00
|
|
|
match link {
|
|
|
|
AssocItemLink::Anchor if !is_static || render_static => {
|
2015-08-16 15:05:18 +00:00
|
|
|
document(w, cx, item)
|
2016-02-28 11:11:13 +00:00
|
|
|
},
|
|
|
|
_ => Ok(()),
|
2013-10-21 18:33:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 19:22:09 +00:00
|
|
|
try!(write!(w, "<div class='impl-items'>"));
|
2015-06-10 16:22:20 +00:00
|
|
|
for trait_item in &i.impl_.items {
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(doctraititem(w, cx, trait_item, link, render_header, outer_version));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2013-10-21 18:33:04 +00:00
|
|
|
|
2015-03-14 18:05:00 +00:00
|
|
|
fn render_default_items(w: &mut fmt::Formatter,
|
2015-08-16 15:05:18 +00:00
|
|
|
cx: &Context,
|
2015-08-16 10:32:28 +00:00
|
|
|
did: DefId,
|
2015-03-14 18:05:00 +00:00
|
|
|
t: &clean::Trait,
|
2015-04-26 19:03:38 +00:00
|
|
|
i: &clean::Impl,
|
2016-02-10 02:15:29 +00:00
|
|
|
render_static: bool,
|
|
|
|
outer_version: Option<&str>) -> fmt::Result {
|
2015-01-31 17:20:46 +00:00
|
|
|
for trait_item in &t.items {
|
2015-03-10 10:28:44 +00:00
|
|
|
let n = trait_item.name.clone();
|
2016-02-28 11:11:13 +00:00
|
|
|
if i.items.iter().find(|m| { m.name == n }).is_some() {
|
|
|
|
continue;
|
2014-05-03 09:08:58 +00:00
|
|
|
}
|
|
|
|
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(doctraititem(w, cx, trait_item, AssocItemLink::GotoSource(did), render_static,
|
|
|
|
outer_version));
|
2014-05-03 09:08:58 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2013-10-21 18:33:04 +00:00
|
|
|
// If we've implemented a trait, then also emit documentation for all
|
|
|
|
// default methods which weren't overridden in the implementation block.
|
2014-11-20 19:22:09 +00:00
|
|
|
// FIXME: this also needs to be done for associated types, whenever defaults
|
|
|
|
// for them work.
|
2015-04-06 22:10:55 +00:00
|
|
|
if let Some(clean::ResolvedPath { did, .. }) = i.impl_.trait_ {
|
|
|
|
if let Some(t) = cache().traits.get(&did) {
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(render_default_items(w, cx, did, t, &i.impl_, render_header, outer_version));
|
2013-10-21 18:33:04 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-19 18:07:49 +00:00
|
|
|
try!(write!(w, "</div>"));
|
2014-01-30 19:30:21 +00:00
|
|
|
Ok(())
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 15:05:18 +00:00
|
|
|
fn item_typedef(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
2014-01-30 19:30:21 +00:00
|
|
|
t: &clean::Typedef) -> fmt::Result {
|
2015-05-25 21:05:35 +00:00
|
|
|
try!(write!(w, "<pre class='rust typedef'>type {}{}{where_clause} = {type_};</pre>",
|
2015-02-02 02:53:25 +00:00
|
|
|
it.name.as_ref().unwrap(),
|
2014-01-30 19:30:21 +00:00
|
|
|
t.generics,
|
2015-05-25 21:05:35 +00:00
|
|
|
where_clause = WhereClause(&t.generics),
|
|
|
|
type_ = t.type_));
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2015-08-16 15:05:18 +00:00
|
|
|
document(w, cx, it)
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
impl<'a> fmt::Display for Sidebar<'a> {
|
2014-02-05 12:55:13 +00:00
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let cx = self.cx;
|
|
|
|
let it = self.item;
|
2015-03-05 07:35:43 +00:00
|
|
|
let parentlen = cx.current.len() - if it.is_mod() {1} else {0};
|
|
|
|
|
2015-03-05 14:10:15 +00:00
|
|
|
// the sidebar is designed to display sibling functions, modules and
|
|
|
|
// other miscellaneous informations. since there are lots of sibling
|
|
|
|
// items (and that causes quadratic growth in large modules),
|
|
|
|
// we refactor common parts into a shared JavaScript file per module.
|
|
|
|
// still, we don't move everything into JS because we want to preserve
|
|
|
|
// as much HTML as possible in order to allow non-JS-enabled browsers
|
|
|
|
// to navigate the documentation (though slightly inefficiently).
|
|
|
|
|
2014-05-10 21:05:06 +00:00
|
|
|
try!(write!(fmt, "<p class='location'>"));
|
2015-03-05 07:35:43 +00:00
|
|
|
for (i, name) in cx.current.iter().take(parentlen).enumerate() {
|
2014-01-30 19:30:21 +00:00
|
|
|
if i > 0 {
|
2014-08-17 18:28:20 +00:00
|
|
|
try!(write!(fmt, "::<wbr>"));
|
2014-01-30 19:30:21 +00:00
|
|
|
}
|
2014-05-10 21:05:06 +00:00
|
|
|
try!(write!(fmt, "<a href='{}index.html'>{}</a>",
|
2015-01-27 02:21:15 +00:00
|
|
|
&cx.root_path[..(cx.current.len() - i - 1) * 3],
|
2014-01-30 19:30:21 +00:00
|
|
|
*name));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
2014-05-10 21:05:06 +00:00
|
|
|
try!(write!(fmt, "</p>"));
|
2013-09-19 05:18:38 +00:00
|
|
|
|
2015-03-05 07:35:43 +00:00
|
|
|
// sidebar refers to the enclosing module, not this module
|
2016-02-28 11:23:07 +00:00
|
|
|
let relpath = if it.is_mod() { "../" } else { "" };
|
2015-03-05 07:35:43 +00:00
|
|
|
try!(write!(fmt,
|
|
|
|
"<script>window.sidebarCurrent = {{\
|
|
|
|
name: '{name}', \
|
|
|
|
ty: '{ty}', \
|
|
|
|
relpath: '{path}'\
|
|
|
|
}};</script>",
|
|
|
|
name = it.name.as_ref().map(|x| &x[..]).unwrap_or(""),
|
|
|
|
ty = shortty(it).to_static_str(),
|
|
|
|
path = relpath));
|
|
|
|
if parentlen == 0 {
|
|
|
|
// there is no sidebar-items.js beyond the crate root path
|
|
|
|
// FIXME maybe dynamic crate loading can be merged here
|
|
|
|
} else {
|
2015-03-07 14:01:31 +00:00
|
|
|
try!(write!(fmt, "<script defer src=\"{path}sidebar-items.js\"></script>",
|
2015-03-05 07:35:43 +00:00
|
|
|
path = relpath));
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
|
2014-01-30 19:30:21 +00:00
|
|
|
Ok(())
|
2013-09-19 05:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
impl<'a> fmt::Display for Source<'a> {
|
2014-02-05 12:55:13 +00:00
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let Source(s) = *self;
|
2014-06-06 06:18:51 +00:00
|
|
|
let lines = s.lines().count();
|
2013-09-27 22:12:23 +00:00
|
|
|
let mut cols = 0;
|
|
|
|
let mut tmp = lines;
|
|
|
|
while tmp > 0 {
|
|
|
|
cols += 1;
|
|
|
|
tmp /= 10;
|
|
|
|
}
|
2014-12-19 18:56:47 +00:00
|
|
|
try!(write!(fmt, "<pre class=\"line-numbers\">"));
|
2015-01-26 20:46:12 +00:00
|
|
|
for i in 1..lines + 1 {
|
2014-12-19 18:56:47 +00:00
|
|
|
try!(write!(fmt, "<span id=\"{0}\">{0:1$}</span>\n", i, cols));
|
2013-09-27 22:12:23 +00:00
|
|
|
}
|
2014-05-10 21:05:06 +00:00
|
|
|
try!(write!(fmt, "</pre>"));
|
2015-02-02 02:53:25 +00:00
|
|
|
try!(write!(fmt, "{}", highlight::highlight(s, None, None)));
|
2014-01-30 19:30:21 +00:00
|
|
|
Ok(())
|
2013-09-27 22:12:23 +00:00
|
|
|
}
|
2013-09-26 18:09:47 +00:00
|
|
|
}
|
2014-02-17 05:40:26 +00:00
|
|
|
|
2015-08-16 15:05:18 +00:00
|
|
|
fn item_macro(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
2014-02-17 05:40:26 +00:00
|
|
|
t: &clean::Macro) -> fmt::Result {
|
2015-02-02 02:53:25 +00:00
|
|
|
try!(w.write_str(&highlight::highlight(&t.source,
|
2014-12-12 18:59:41 +00:00
|
|
|
Some("macro"),
|
2015-02-02 02:53:25 +00:00
|
|
|
None)));
|
2016-02-10 02:15:29 +00:00
|
|
|
try!(render_stability_since_raw(w, it.stable_since(), None));
|
2015-08-16 15:05:18 +00:00
|
|
|
document(w, cx, it)
|
2014-02-17 05:40:26 +00:00
|
|
|
}
|
2014-05-29 02:53:37 +00:00
|
|
|
|
2015-08-16 15:05:18 +00:00
|
|
|
fn item_primitive(w: &mut fmt::Formatter, cx: &Context,
|
2014-05-29 02:53:37 +00:00
|
|
|
it: &clean::Item,
|
2014-09-11 05:07:49 +00:00
|
|
|
_p: &clean::PrimitiveType) -> fmt::Result {
|
2015-08-16 15:05:18 +00:00
|
|
|
try!(document(w, cx, it));
|
2016-02-10 02:15:29 +00:00
|
|
|
render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
|
2014-05-29 02:53:37 +00:00
|
|
|
}
|
2014-05-29 20:50:47 +00:00
|
|
|
|
2016-02-28 13:01:43 +00:00
|
|
|
const BASIC_KEYWORDS: &'static str = "rust, rustlang, rust-lang";
|
2014-08-04 21:30:06 +00:00
|
|
|
|
|
|
|
fn make_item_keywords(it: &clean::Item) -> String {
|
2016-02-28 13:01:43 +00:00
|
|
|
format!("{}, {}", BASIC_KEYWORDS, it.name.as_ref().unwrap())
|
2014-08-04 21:30:06 +00:00
|
|
|
}
|
2014-11-14 22:20:57 +00:00
|
|
|
|
2015-02-25 23:03:06 +00:00
|
|
|
fn get_index_search_type(item: &clean::Item,
|
|
|
|
parent: Option<String>) -> Option<IndexItemFunctionType> {
|
2016-02-23 11:04:27 +00:00
|
|
|
let (decl, selfty) = match item.inner {
|
|
|
|
clean::FunctionItem(ref f) => (&f.decl, None),
|
|
|
|
clean::MethodItem(ref m) => (&m.decl, Some(&m.self_)),
|
|
|
|
clean::TyMethodItem(ref m) => (&m.decl, Some(&m.self_)),
|
2015-02-25 23:03:06 +00:00
|
|
|
_ => return None
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut inputs = Vec::new();
|
|
|
|
|
|
|
|
// Consider `self` an argument as well.
|
2016-02-23 11:04:27 +00:00
|
|
|
match parent.and_then(|p| selfty.map(|s| (p, s)) ) {
|
|
|
|
Some((_, &clean::SelfStatic)) | None => (),
|
|
|
|
Some((name, _)) => inputs.push(Type { name: Some(name.to_ascii_lowercase()) }),
|
2015-02-25 23:03:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inputs.extend(&mut decl.inputs.values.iter().map(|arg| {
|
|
|
|
get_index_type(&arg.type_)
|
|
|
|
}));
|
|
|
|
|
|
|
|
let output = match decl.output {
|
|
|
|
clean::FunctionRetTy::Return(ref return_type) => Some(get_index_type(return_type)),
|
|
|
|
_ => None
|
|
|
|
};
|
|
|
|
|
|
|
|
Some(IndexItemFunctionType { inputs: inputs, output: output })
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_index_type(clean_type: &clean::Type) -> Type {
|
2015-07-08 15:33:13 +00:00
|
|
|
Type { name: get_index_type_name(clean_type).map(|s| s.to_ascii_lowercase()) }
|
2015-02-25 23:03:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_index_type_name(clean_type: &clean::Type) -> Option<String> {
|
|
|
|
match *clean_type {
|
|
|
|
clean::ResolvedPath { ref path, .. } => {
|
|
|
|
let segments = &path.segments;
|
|
|
|
Some(segments[segments.len() - 1].name.clone())
|
|
|
|
},
|
|
|
|
clean::Generic(ref s) => Some(s.clone()),
|
|
|
|
clean::Primitive(ref p) => Some(format!("{:?}", p)),
|
|
|
|
clean::BorrowedRef { ref type_, .. } => get_index_type_name(type_),
|
|
|
|
// FIXME: add all from clean::Type.
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-14 22:20:57 +00:00
|
|
|
pub fn cache() -> Arc<Cache> {
|
|
|
|
CACHE_KEY.with(|c| c.borrow().clone())
|
|
|
|
}
|
2015-12-05 22:09:20 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
#[test]
|
|
|
|
fn test_unique_id() {
|
|
|
|
let input = ["foo", "examples", "examples", "method.into_iter","examples",
|
|
|
|
"method.into_iter", "foo", "main", "search", "methods",
|
|
|
|
"examples", "method.into_iter", "assoc_type.Item", "assoc_type.Item"];
|
|
|
|
let expected = ["foo", "examples", "examples-1", "method.into_iter", "examples-2",
|
|
|
|
"method.into_iter-1", "foo-1", "main-1", "search-1", "methods-1",
|
|
|
|
"examples-3", "method.into_iter-2", "assoc_type.Item", "assoc_type.Item-1"];
|
|
|
|
|
|
|
|
let test = || {
|
|
|
|
let actual: Vec<String> = input.iter().map(|s| derive_id(s.to_string())).collect();
|
|
|
|
assert_eq!(&actual[..], expected);
|
|
|
|
};
|
|
|
|
test();
|
|
|
|
reset_ids();
|
|
|
|
test();
|
|
|
|
}
|