rustdoc: Remove io_error usage
This commit is contained in:
parent
e0f0a2f67f
commit
6132f7f666
7 changed files with 494 additions and 415 deletions
|
@ -20,7 +20,7 @@ use std::fmt;
|
||||||
pub struct Escape<'a>(&'a str);
|
pub struct Escape<'a>(&'a str);
|
||||||
|
|
||||||
impl<'a> fmt::Show for Escape<'a> {
|
impl<'a> fmt::Show for Escape<'a> {
|
||||||
fn fmt(s: &Escape<'a>, fmt: &mut fmt::Formatter) {
|
fn fmt(s: &Escape<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
// Because the internet is always right, turns out there's not that many
|
// Because the internet is always right, turns out there's not that many
|
||||||
// characters to escape: http://stackoverflow.com/questions/7381974
|
// characters to escape: http://stackoverflow.com/questions/7381974
|
||||||
let Escape(s) = *s;
|
let Escape(s) = *s;
|
||||||
|
@ -29,7 +29,7 @@ impl<'a> fmt::Show for Escape<'a> {
|
||||||
for (i, ch) in s.bytes().enumerate() {
|
for (i, ch) in s.bytes().enumerate() {
|
||||||
match ch as char {
|
match ch as char {
|
||||||
'<' | '>' | '&' | '\'' | '"' => {
|
'<' | '>' | '&' | '\'' | '"' => {
|
||||||
fmt.buf.write(pile_o_bits.slice(last, i).as_bytes());
|
if_ok!(fmt.buf.write(pile_o_bits.slice(last, i).as_bytes()));
|
||||||
let s = match ch as char {
|
let s = match ch as char {
|
||||||
'>' => ">",
|
'>' => ">",
|
||||||
'<' => "<",
|
'<' => "<",
|
||||||
|
@ -38,7 +38,7 @@ impl<'a> fmt::Show for Escape<'a> {
|
||||||
'"' => """,
|
'"' => """,
|
||||||
_ => unreachable!()
|
_ => unreachable!()
|
||||||
};
|
};
|
||||||
fmt.buf.write(s.as_bytes());
|
if_ok!(fmt.buf.write(s.as_bytes()));
|
||||||
last = i + 1;
|
last = i + 1;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -46,7 +46,8 @@ impl<'a> fmt::Show for Escape<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if last < s.len() {
|
if last < s.len() {
|
||||||
fmt.buf.write(pile_o_bits.slice_from(last).as_bytes());
|
if_ok!(fmt.buf.write(pile_o_bits.slice_from(last).as_bytes()));
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,85 +48,105 @@ impl PuritySpace {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for clean::Generics {
|
impl fmt::Show for clean::Generics {
|
||||||
fn fmt(g: &clean::Generics, f: &mut fmt::Formatter) {
|
impl fmt::Default for clean::Generics {
|
||||||
if g.lifetimes.len() == 0 && g.type_params.len() == 0 { return }
|
fn fmt(g: &clean::Generics, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
f.buf.write("<".as_bytes());
|
if g.lifetimes.len() == 0 && g.type_params.len() == 0 { return Ok(()) }
|
||||||
|
if_ok!(f.buf.write("<".as_bytes()));
|
||||||
|
|
||||||
for (i, life) in g.lifetimes.iter().enumerate() {
|
for (i, life) in g.lifetimes.iter().enumerate() {
|
||||||
if i > 0 { f.buf.write(", ".as_bytes()); }
|
if i > 0 {
|
||||||
write!(f.buf, "{}", *life);
|
if_ok!(f.buf.write(", ".as_bytes()));
|
||||||
|
}
|
||||||
|
if_ok!(write!(f.buf, "{}", *life));
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.type_params.len() > 0 {
|
if g.type_params.len() > 0 {
|
||||||
if g.lifetimes.len() > 0 { f.buf.write(", ".as_bytes()); }
|
if g.lifetimes.len() > 0 {
|
||||||
|
if_ok!(f.buf.write(", ".as_bytes()));
|
||||||
|
}
|
||||||
|
|
||||||
for (i, tp) in g.type_params.iter().enumerate() {
|
for (i, tp) in g.type_params.iter().enumerate() {
|
||||||
if i > 0 { f.buf.write(", ".as_bytes()) }
|
if i > 0 {
|
||||||
f.buf.write(tp.name.as_bytes());
|
if_ok!(f.buf.write(", ".as_bytes()))
|
||||||
|
}
|
||||||
|
if_ok!(f.buf.write(tp.name.as_bytes()));
|
||||||
|
|
||||||
if tp.bounds.len() > 0 {
|
if tp.bounds.len() > 0 {
|
||||||
f.buf.write(": ".as_bytes());
|
if_ok!(f.buf.write(": ".as_bytes()));
|
||||||
for (i, bound) in tp.bounds.iter().enumerate() {
|
for (i, bound) in tp.bounds.iter().enumerate() {
|
||||||
if i > 0 { f.buf.write(" + ".as_bytes()); }
|
if i > 0 {
|
||||||
write!(f.buf, "{}", *bound);
|
if_ok!(f.buf.write(" + ".as_bytes()));
|
||||||
|
}
|
||||||
|
if_ok!(write!(f.buf, "{}", *bound));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.buf.write(">".as_bytes());
|
if_ok!(f.buf.write(">".as_bytes()));
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for clean::Lifetime {
|
impl fmt::Show for clean::Lifetime {
|
||||||
fn fmt(l: &clean::Lifetime, f: &mut fmt::Formatter) {
|
fn fmt(l: &clean::Lifetime, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
f.buf.write("'".as_bytes());
|
if_ok!(f.buf.write("'".as_bytes()));
|
||||||
f.buf.write(l.get_ref().as_bytes());
|
if_ok!(f.buf.write(l.get_ref().as_bytes()));
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for clean::TyParamBound {
|
impl fmt::Show for clean::TyParamBound {
|
||||||
fn fmt(bound: &clean::TyParamBound, f: &mut fmt::Formatter) {
|
fn fmt(bound: &clean::TyParamBound, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *bound {
|
match *bound {
|
||||||
clean::RegionBound => {
|
clean::RegionBound => {
|
||||||
f.buf.write("'static".as_bytes())
|
f.buf.write("'static".as_bytes())
|
||||||
}
|
}
|
||||||
clean::TraitBound(ref ty) => {
|
clean::TraitBound(ref ty) => {
|
||||||
write!(f.buf, "{}", *ty);
|
write!(f.buf, "{}", *ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for clean::Path {
|
impl fmt::Show for clean::Path {
|
||||||
fn fmt(path: &clean::Path, f: &mut fmt::Formatter) {
|
fn fmt(path: &clean::Path, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
if path.global { f.buf.write("::".as_bytes()) }
|
if path.global {
|
||||||
|
if_ok!(f.buf.write("::".as_bytes()))
|
||||||
|
}
|
||||||
for (i, seg) in path.segments.iter().enumerate() {
|
for (i, seg) in path.segments.iter().enumerate() {
|
||||||
if i > 0 { f.buf.write("::".as_bytes()) }
|
if i > 0 {
|
||||||
f.buf.write(seg.name.as_bytes());
|
if_ok!(f.buf.write("::".as_bytes()))
|
||||||
|
}
|
||||||
|
if_ok!(f.buf.write(seg.name.as_bytes()));
|
||||||
|
|
||||||
if seg.lifetimes.len() > 0 || seg.types.len() > 0 {
|
if seg.lifetimes.len() > 0 || seg.types.len() > 0 {
|
||||||
f.buf.write("<".as_bytes());
|
if_ok!(f.buf.write("<".as_bytes()));
|
||||||
let mut comma = false;
|
let mut comma = false;
|
||||||
for lifetime in seg.lifetimes.iter() {
|
for lifetime in seg.lifetimes.iter() {
|
||||||
if comma { f.buf.write(", ".as_bytes()); }
|
if comma {
|
||||||
|
if_ok!(f.buf.write(", ".as_bytes()));
|
||||||
|
}
|
||||||
comma = true;
|
comma = true;
|
||||||
write!(f.buf, "{}", *lifetime);
|
if_ok!(write!(f.buf, "{}", *lifetime));
|
||||||
}
|
}
|
||||||
for ty in seg.types.iter() {
|
for ty in seg.types.iter() {
|
||||||
if comma { f.buf.write(", ".as_bytes()); }
|
if comma {
|
||||||
|
if_ok!(f.buf.write(", ".as_bytes()));
|
||||||
|
}
|
||||||
comma = true;
|
comma = true;
|
||||||
write!(f.buf, "{}", *ty);
|
if_ok!(write!(f.buf, "{}", *ty));
|
||||||
}
|
}
|
||||||
f.buf.write(">".as_bytes());
|
if_ok!(f.buf.write(">".as_bytes()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used when rendering a `ResolvedPath` structure. This invokes the `path`
|
/// Used when rendering a `ResolvedPath` structure. This invokes the `path`
|
||||||
/// rendering function with the necessary arguments for linking to a local path.
|
/// rendering function with the necessary arguments for linking to a local path.
|
||||||
fn resolved_path(w: &mut io::Writer, id: ast::NodeId, p: &clean::Path,
|
fn resolved_path(w: &mut io::Writer, id: ast::NodeId, p: &clean::Path,
|
||||||
print_all: bool) {
|
print_all: bool) -> fmt::Result {
|
||||||
path(w, p, print_all,
|
path(w, p, print_all,
|
||||||
|_cache, loc| { Some("../".repeat(loc.len())) },
|
|_cache, loc| { Some("../".repeat(loc.len())) },
|
||||||
|cache| {
|
|cache| {
|
||||||
|
@ -134,13 +154,14 @@ fn resolved_path(w: &mut io::Writer, id: ast::NodeId, p: &clean::Path,
|
||||||
None => None,
|
None => None,
|
||||||
Some(&(ref fqp, shortty)) => Some((fqp.clone(), shortty))
|
Some(&(ref fqp, shortty)) => Some((fqp.clone(), shortty))
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used when rendering an `ExternalPath` structure. Like `resolved_path` this
|
/// Used when rendering an `ExternalPath` structure. Like `resolved_path` this
|
||||||
/// will invoke `path` with proper linking-style arguments.
|
/// will invoke `path` with proper linking-style arguments.
|
||||||
fn external_path(w: &mut io::Writer, p: &clean::Path, print_all: bool,
|
fn external_path(w: &mut io::Writer, p: &clean::Path, print_all: bool,
|
||||||
fqn: &[~str], kind: clean::TypeKind, crate: ast::CrateNum) {
|
fqn: &[~str], kind: clean::TypeKind,
|
||||||
|
crate: ast::CrateNum) -> fmt::Result {
|
||||||
path(w, p, print_all,
|
path(w, p, print_all,
|
||||||
|cache, loc| {
|
|cache, loc| {
|
||||||
match *cache.extern_locations.get(&crate) {
|
match *cache.extern_locations.get(&crate) {
|
||||||
|
@ -161,7 +182,9 @@ fn external_path(w: &mut io::Writer, p: &clean::Path, print_all: bool,
|
||||||
|
|
||||||
fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
|
fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
|
||||||
root: |&render::Cache, &[~str]| -> Option<~str>,
|
root: |&render::Cache, &[~str]| -> Option<~str>,
|
||||||
info: |&render::Cache| -> Option<(~[~str], &'static str)>) {
|
info: |&render::Cache| -> Option<(~[~str], &'static str)>)
|
||||||
|
-> fmt::Result
|
||||||
|
{
|
||||||
// The generics will get written to both the title and link
|
// The generics will get written to both the title and link
|
||||||
let mut generics = ~"";
|
let mut generics = ~"";
|
||||||
let last = path.segments.last().unwrap();
|
let last = path.segments.last().unwrap();
|
||||||
|
@ -200,20 +223,20 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
|
||||||
let mut root = root;
|
let mut root = root;
|
||||||
for seg in path.segments.slice_to(amt).iter() {
|
for seg in path.segments.slice_to(amt).iter() {
|
||||||
if "super" == seg.name || "self" == seg.name {
|
if "super" == seg.name || "self" == seg.name {
|
||||||
write!(w, "{}::", seg.name);
|
if_ok!(write!(w, "{}::", seg.name));
|
||||||
} else {
|
} else {
|
||||||
root.push_str(seg.name);
|
root.push_str(seg.name);
|
||||||
root.push_str("/");
|
root.push_str("/");
|
||||||
write!(w, "<a class='mod'
|
if_ok!(write!(w, "<a class='mod'
|
||||||
href='{}index.html'>{}</a>::",
|
href='{}index.html'>{}</a>::",
|
||||||
root,
|
root,
|
||||||
seg.name);
|
seg.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
for seg in path.segments.slice_to(amt).iter() {
|
for seg in path.segments.slice_to(amt).iter() {
|
||||||
write!(w, "{}::", seg.name);
|
if_ok!(write!(w, "{}::", seg.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,51 +264,57 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(w, "<a class='{}' href='{}' title='{}'>{}</a>",
|
if_ok!(write!(w, "<a class='{}' href='{}' title='{}'>{}</a>",
|
||||||
shortty, url, fqp.connect("::"), last.name);
|
shortty, url, fqp.connect("::"), last.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
write!(w, "{}", last.name);
|
if_ok!(write!(w, "{}", last.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
write!(w, "{}", generics);
|
if_ok!(write!(w, "{}", generics));
|
||||||
|
Ok(())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper to render type parameters
|
/// Helper to render type parameters
|
||||||
fn typarams(w: &mut io::Writer, typarams: &Option<~[clean::TyParamBound]>) {
|
fn typarams(w: &mut io::Writer,
|
||||||
|
typarams: &Option<~[clean::TyParamBound]>) -> fmt::Result {
|
||||||
match *typarams {
|
match *typarams {
|
||||||
Some(ref params) => {
|
Some(ref params) => {
|
||||||
write!(w, "<");
|
if_ok!(write!(w, "<"));
|
||||||
for (i, param) in params.iter().enumerate() {
|
for (i, param) in params.iter().enumerate() {
|
||||||
if i > 0 { write!(w, ", "); }
|
if i > 0 {
|
||||||
write!(w, "{}", *param);
|
if_ok!(write!(w, ", "));
|
||||||
}
|
}
|
||||||
write!(w, ">");
|
if_ok!(write!(w, "{}", *param));
|
||||||
}
|
}
|
||||||
None => {}
|
if_ok!(write!(w, ">"));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
None => Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for clean::Type {
|
impl fmt::Show for clean::Type {
|
||||||
fn fmt(g: &clean::Type, f: &mut fmt::Formatter) {
|
fn fmt(g: &clean::Type, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *g {
|
match *g {
|
||||||
clean::TyParamBinder(id) | clean::Generic(id) => {
|
clean::TyParamBinder(id) | clean::Generic(id) => {
|
||||||
local_data::get(cache_key, |cache| {
|
local_data::get(cache_key, |cache| {
|
||||||
let m = cache.unwrap().get();
|
let m = cache.unwrap().get();
|
||||||
f.buf.write(m.typarams.get(&id).as_bytes());
|
f.buf.write(m.typarams.get(&id).as_bytes())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
clean::ResolvedPath{id, typarams: ref tp, path: ref path} => {
|
clean::ResolvedPath{id, typarams: ref tp, path: ref path} => {
|
||||||
resolved_path(f.buf, id, path, false);
|
if_ok!(resolved_path(f.buf, id, path, false));
|
||||||
typarams(f.buf, tp);
|
typarams(f.buf, tp)
|
||||||
}
|
}
|
||||||
clean::ExternalPath{path: ref path, typarams: ref tp,
|
clean::ExternalPath{path: ref path, typarams: ref tp,
|
||||||
fqn: ref fqn, kind, crate} => {
|
fqn: ref fqn, kind, crate} => {
|
||||||
external_path(f.buf, path, false, fqn.as_slice(), kind, crate);
|
if_ok!(external_path(f.buf, path, false, fqn.as_slice(), kind,
|
||||||
typarams(f.buf, tp);
|
crate))
|
||||||
|
typarams(f.buf, tp)
|
||||||
}
|
}
|
||||||
clean::Self(..) => f.buf.write("Self".as_bytes()),
|
clean::Self(..) => f.buf.write("Self".as_bytes()),
|
||||||
clean::Primitive(prim) => {
|
clean::Primitive(prim) => {
|
||||||
|
@ -306,7 +335,7 @@ impl fmt::Show for clean::Type {
|
||||||
ast::TyBool => "bool",
|
ast::TyBool => "bool",
|
||||||
ast::TyChar => "char",
|
ast::TyChar => "char",
|
||||||
};
|
};
|
||||||
f.buf.write(s.as_bytes());
|
f.buf.write(s.as_bytes())
|
||||||
}
|
}
|
||||||
clean::Closure(ref decl) => {
|
clean::Closure(ref decl) => {
|
||||||
let region = match decl.region {
|
let region = match decl.region {
|
||||||
|
@ -322,7 +351,7 @@ impl fmt::Show for clean::Type {
|
||||||
ast::ManagedSigil => format!("@{}fn({})", region, decl.decl.inputs),
|
ast::ManagedSigil => format!("@{}fn({})", region, decl.decl.inputs),
|
||||||
},
|
},
|
||||||
arrow = match decl.decl.output { clean::Unit => "no", _ => "yes" },
|
arrow = match decl.decl.output { clean::Unit => "no", _ => "yes" },
|
||||||
ret = decl.decl.output);
|
ret = decl.decl.output)
|
||||||
// FIXME: where are bounds and lifetimes printed?!
|
// FIXME: where are bounds and lifetimes printed?!
|
||||||
}
|
}
|
||||||
clean::BareFunction(ref decl) => {
|
clean::BareFunction(ref decl) => {
|
||||||
|
@ -333,19 +362,21 @@ impl fmt::Show for clean::Type {
|
||||||
ref s => " " + *s + " ",
|
ref s => " " + *s + " ",
|
||||||
},
|
},
|
||||||
decl.generics,
|
decl.generics,
|
||||||
decl.decl);
|
decl.decl)
|
||||||
}
|
}
|
||||||
clean::Tuple(ref typs) => {
|
clean::Tuple(ref typs) => {
|
||||||
f.buf.write("(".as_bytes());
|
if_ok!(f.buf.write("(".as_bytes()));
|
||||||
for (i, typ) in typs.iter().enumerate() {
|
for (i, typ) in typs.iter().enumerate() {
|
||||||
if i > 0 { f.buf.write(", ".as_bytes()) }
|
if i > 0 {
|
||||||
write!(f.buf, "{}", *typ);
|
if_ok!(f.buf.write(", ".as_bytes()))
|
||||||
}
|
}
|
||||||
f.buf.write(")".as_bytes());
|
if_ok!(write!(f.buf, "{}", *typ));
|
||||||
|
}
|
||||||
|
f.buf.write(")".as_bytes())
|
||||||
}
|
}
|
||||||
clean::Vector(ref t) => write!(f.buf, "[{}]", **t),
|
clean::Vector(ref t) => write!(f.buf, "[{}]", **t),
|
||||||
clean::FixedVector(ref t, ref s) => {
|
clean::FixedVector(ref t, ref s) => {
|
||||||
write!(f.buf, "[{}, ..{}]", **t, *s);
|
write!(f.buf, "[{}, ..{}]", **t, *s)
|
||||||
}
|
}
|
||||||
clean::String => f.buf.write("str".as_bytes()),
|
clean::String => f.buf.write("str".as_bytes()),
|
||||||
clean::Bool => f.buf.write("bool".as_bytes()),
|
clean::Bool => f.buf.write("bool".as_bytes()),
|
||||||
|
@ -368,23 +399,23 @@ impl fmt::Show for clean::Type {
|
||||||
clean::Mutable => "mut ",
|
clean::Mutable => "mut ",
|
||||||
clean::Immutable => "",
|
clean::Immutable => "",
|
||||||
},
|
},
|
||||||
**ty);
|
**ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for clean::FnDecl {
|
impl fmt::Show for clean::FnDecl {
|
||||||
fn fmt(d: &clean::FnDecl, f: &mut fmt::Formatter) {
|
fn fmt(d: &clean::FnDecl, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f.buf, "({args}){arrow, select, yes{ -> {ret}} other{}}",
|
write!(f.buf, "({args}){arrow, select, yes{ -> {ret}} other{}}",
|
||||||
args = d.inputs,
|
args = d.inputs,
|
||||||
arrow = match d.output { clean::Unit => "no", _ => "yes" },
|
arrow = match d.output { clean::Unit => "no", _ => "yes" },
|
||||||
ret = d.output);
|
ret = d.output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for ~[clean::Argument] {
|
impl fmt::Show for ~[clean::Argument] {
|
||||||
fn fmt(inputs: &~[clean::Argument], f: &mut fmt::Formatter) {
|
fn fmt(inputs: &~[clean::Argument], f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let mut args = ~"";
|
let mut args = ~"";
|
||||||
for (i, input) in inputs.iter().enumerate() {
|
for (i, input) in inputs.iter().enumerate() {
|
||||||
if i > 0 { args.push_str(", "); }
|
if i > 0 { args.push_str(", "); }
|
||||||
|
@ -393,12 +424,12 @@ impl fmt::Show for ~[clean::Argument] {
|
||||||
}
|
}
|
||||||
args.push_str(format!("{}", input.type_));
|
args.push_str(format!("{}", input.type_));
|
||||||
}
|
}
|
||||||
f.buf.write(args.as_bytes());
|
f.buf.write(args.as_bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> fmt::Show for Method<'a> {
|
impl<'a> fmt::Show for Method<'a> {
|
||||||
fn fmt(m: &Method<'a>, f: &mut fmt::Formatter) {
|
fn fmt(m: &Method<'a>, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let Method(selfty, d) = *m;
|
let Method(selfty, d) = *m;
|
||||||
let mut args = ~"";
|
let mut args = ~"";
|
||||||
match *selfty {
|
match *selfty {
|
||||||
|
@ -429,74 +460,79 @@ impl<'a> fmt::Show for Method<'a> {
|
||||||
write!(f.buf, "({args}){arrow, select, yes{ -> {ret}} other{}}",
|
write!(f.buf, "({args}){arrow, select, yes{ -> {ret}} other{}}",
|
||||||
args = args,
|
args = args,
|
||||||
arrow = match d.output { clean::Unit => "no", _ => "yes" },
|
arrow = match d.output { clean::Unit => "no", _ => "yes" },
|
||||||
ret = d.output);
|
ret = d.output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for VisSpace {
|
impl fmt::Show for VisSpace {
|
||||||
fn fmt(v: &VisSpace, f: &mut fmt::Formatter) {
|
fn fmt(v: &VisSpace, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match v.get() {
|
match v.get() {
|
||||||
Some(ast::Public) => { write!(f.buf, "pub "); }
|
Some(ast::Public) => write!(f.buf, "pub "),
|
||||||
Some(ast::Private) => { write!(f.buf, "priv "); }
|
Some(ast::Private) => write!(f.buf, "priv "),
|
||||||
Some(ast::Inherited) | None => {}
|
Some(ast::Inherited) | None => Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for PuritySpace {
|
impl fmt::Show for PuritySpace {
|
||||||
fn fmt(p: &PuritySpace, f: &mut fmt::Formatter) {
|
fn fmt(p: &PuritySpace, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match p.get() {
|
match p.get() {
|
||||||
ast::UnsafeFn => write!(f.buf, "unsafe "),
|
ast::UnsafeFn => write!(f.buf, "unsafe "),
|
||||||
ast::ExternFn => write!(f.buf, "extern "),
|
ast::ExternFn => write!(f.buf, "extern "),
|
||||||
ast::ImpureFn => {}
|
ast::ImpureFn => Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for clean::ViewPath {
|
impl fmt::Show for clean::ViewPath {
|
||||||
fn fmt(v: &clean::ViewPath, f: &mut fmt::Formatter) {
|
fn fmt(v: &clean::ViewPath, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *v {
|
match *v {
|
||||||
clean::SimpleImport(ref name, ref src) => {
|
clean::SimpleImport(ref name, ref src) => {
|
||||||
if *name == src.path.segments.last().unwrap().name {
|
if *name == src.path.segments.last().unwrap().name {
|
||||||
write!(f.buf, "use {};", *src);
|
write!(f.buf, "use {};", *src)
|
||||||
} else {
|
} else {
|
||||||
write!(f.buf, "use {} = {};", *name, *src);
|
write!(f.buf, "use {} = {};", *name, *src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clean::GlobImport(ref src) => {
|
clean::GlobImport(ref src) => {
|
||||||
write!(f.buf, "use {}::*;", *src);
|
write!(f.buf, "use {}::*;", *src)
|
||||||
}
|
}
|
||||||
clean::ImportList(ref src, ref names) => {
|
clean::ImportList(ref src, ref names) => {
|
||||||
write!(f.buf, "use {}::\\{", *src);
|
if_ok!(write!(f.buf, "use {}::\\{", *src));
|
||||||
for (i, n) in names.iter().enumerate() {
|
for (i, n) in names.iter().enumerate() {
|
||||||
if i > 0 { write!(f.buf, ", "); }
|
if i > 0 {
|
||||||
write!(f.buf, "{}", *n);
|
if_ok!(write!(f.buf, ", "));
|
||||||
}
|
}
|
||||||
write!(f.buf, "\\};");
|
if_ok!(write!(f.buf, "{}", *n));
|
||||||
|
}
|
||||||
|
write!(f.buf, "\\};")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for clean::ImportSource {
|
impl fmt::Show for clean::ImportSource {
|
||||||
fn fmt(v: &clean::ImportSource, f: &mut fmt::Formatter) {
|
fn fmt(v: &clean::ImportSource, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match v.did {
|
match v.did {
|
||||||
// FIXME: shouldn't be restricted to just local imports
|
// FIXME: shouldn't be restricted to just local imports
|
||||||
Some(did) if ast_util::is_local(did) => {
|
Some(did) if ast_util::is_local(did) => {
|
||||||
resolved_path(f.buf, did.node, &v.path, true);
|
resolved_path(f.buf, did.node, &v.path, true)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
for (i, seg) in v.path.segments.iter().enumerate() {
|
for (i, seg) in v.path.segments.iter().enumerate() {
|
||||||
if i > 0 { write!(f.buf, "::") }
|
if i > 0 {
|
||||||
write!(f.buf, "{}", seg.name);
|
if_ok!(write!(f.buf, "::"))
|
||||||
}
|
}
|
||||||
|
if_ok!(write!(f.buf, "{}", seg.name));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for clean::ViewListIdent {
|
impl fmt::Show for clean::ViewListIdent {
|
||||||
fn fmt(v: &clean::ViewListIdent, f: &mut fmt::Formatter) {
|
fn fmt(v: &clean::ViewListIdent, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match v.source {
|
match v.source {
|
||||||
// FIXME: shouldn't be limited to just local imports
|
// FIXME: shouldn't be limited to just local imports
|
||||||
Some(did) if ast_util::is_local(did) => {
|
Some(did) if ast_util::is_local(did) => {
|
||||||
|
@ -508,7 +544,7 @@ impl fmt::Show for clean::ViewListIdent {
|
||||||
types: ~[],
|
types: ~[],
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
resolved_path(f.buf, did.node, &path, false);
|
resolved_path(f.buf, did.node, &path, false)
|
||||||
}
|
}
|
||||||
_ => write!(f.buf, "{}", v.name),
|
_ => write!(f.buf, "{}", v.name),
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ pub struct Page<'a> {
|
||||||
|
|
||||||
pub fn render<T: fmt::Show, S: fmt::Show>(
|
pub fn render<T: fmt::Show, S: fmt::Show>(
|
||||||
dst: &mut io::Writer, layout: &Layout, page: &Page, sidebar: &S, t: &T)
|
dst: &mut io::Writer, layout: &Layout, page: &Page, sidebar: &S, t: &T)
|
||||||
|
-> fmt::Result
|
||||||
{
|
{
|
||||||
write!(dst,
|
write!(dst,
|
||||||
"<!DOCTYPE html>
|
"<!DOCTYPE html>
|
||||||
|
@ -121,7 +122,7 @@ pub fn render<T: fmt::Show, S: fmt::Show>(
|
||||||
favicon = nonestr(layout.favicon),
|
favicon = nonestr(layout.favicon),
|
||||||
sidebar = *sidebar,
|
sidebar = *sidebar,
|
||||||
crate = layout.crate,
|
crate = layout.crate,
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nonestr<'a>(s: &'a str) -> &'a str {
|
fn nonestr<'a>(s: &'a str) -> &'a str {
|
||||||
|
|
|
@ -109,7 +109,7 @@ fn stripped_filtered_line<'a>(s: &'a str) -> Option<&'a str> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(w: &mut io::Writer, s: &str) {
|
pub fn render(w: &mut io::Writer, s: &str) -> fmt::Result {
|
||||||
extern fn block(ob: *buf, text: *buf, lang: *buf, opaque: *libc::c_void) {
|
extern fn block(ob: *buf, text: *buf, lang: *buf, opaque: *libc::c_void) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let my_opaque: &my_opaque = cast::transmute(opaque);
|
let my_opaque: &my_opaque = cast::transmute(opaque);
|
||||||
|
@ -159,11 +159,12 @@ pub fn render(w: &mut io::Writer, s: &str) {
|
||||||
sd_markdown_render(ob, s.as_ptr(), s.len() as libc::size_t, markdown);
|
sd_markdown_render(ob, s.as_ptr(), s.len() as libc::size_t, markdown);
|
||||||
sd_markdown_free(markdown);
|
sd_markdown_free(markdown);
|
||||||
|
|
||||||
vec::raw::buf_as_slice((*ob).data, (*ob).size as uint, |buf| {
|
let ret = vec::raw::buf_as_slice((*ob).data, (*ob).size as uint, |buf| {
|
||||||
w.write(buf);
|
w.write(buf)
|
||||||
});
|
});
|
||||||
|
|
||||||
bufrelease(ob);
|
bufrelease(ob);
|
||||||
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,10 +211,10 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> fmt::Show for Markdown<'a> {
|
impl<'a> fmt::Show for Markdown<'a> {
|
||||||
fn fmt(md: &Markdown<'a>, fmt: &mut fmt::Formatter) {
|
fn fmt(md: &Markdown<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let Markdown(md) = *md;
|
let Markdown(md) = *md;
|
||||||
// This is actually common enough to special-case
|
// This is actually common enough to special-case
|
||||||
if md.len() == 0 { return; }
|
if md.len() == 0 { return Ok(()) }
|
||||||
render(fmt.buf, md.as_slice());
|
render(fmt.buf, md.as_slice())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -162,10 +162,16 @@ pub fn main_args(args: &[~str]) -> int {
|
||||||
let output = matches.opt_str("o").map(|s| Path::new(s));
|
let output = matches.opt_str("o").map(|s| Path::new(s));
|
||||||
match matches.opt_str("w") {
|
match matches.opt_str("w") {
|
||||||
Some(~"html") | None => {
|
Some(~"html") | None => {
|
||||||
html::render::run(crate, output.unwrap_or(Path::new("doc")))
|
match html::render::run(crate, output.unwrap_or(Path::new("doc"))) {
|
||||||
|
Ok(()) => {}
|
||||||
|
Err(e) => fail!("failed to generate documentation: {}", e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Some(~"json") => {
|
Some(~"json") => {
|
||||||
json_output(crate, res, output.unwrap_or(Path::new("doc.json")))
|
match json_output(crate, res, output.unwrap_or(Path::new("doc.json"))) {
|
||||||
|
Ok(()) => {}
|
||||||
|
Err(e) => fail!("failed to write json: {}", e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
println!("unknown output format: {}", s);
|
println!("unknown output format: {}", s);
|
||||||
|
@ -276,8 +282,8 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
|
||||||
/// run over the deserialized output.
|
/// run over the deserialized output.
|
||||||
fn json_input(input: &str) -> Result<Output, ~str> {
|
fn json_input(input: &str) -> Result<Output, ~str> {
|
||||||
let mut input = match File::open(&Path::new(input)) {
|
let mut input = match File::open(&Path::new(input)) {
|
||||||
Some(f) => f,
|
Ok(f) => f,
|
||||||
None => return Err(format!("couldn't open {} for reading", input)),
|
Err(e) => return Err(format!("couldn't open {}: {}", input, e)),
|
||||||
};
|
};
|
||||||
match json::from_reader(&mut input) {
|
match json::from_reader(&mut input) {
|
||||||
Err(s) => Err(s.to_str()),
|
Err(s) => Err(s.to_str()),
|
||||||
|
@ -312,7 +318,8 @@ fn json_input(input: &str) -> Result<Output, ~str> {
|
||||||
|
|
||||||
/// Outputs the crate/plugin json as a giant json blob at the specified
|
/// Outputs the crate/plugin json as a giant json blob at the specified
|
||||||
/// destination.
|
/// destination.
|
||||||
fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson], dst: Path) {
|
fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson],
|
||||||
|
dst: Path) -> io::IoResult<()> {
|
||||||
// {
|
// {
|
||||||
// "schema": version,
|
// "schema": version,
|
||||||
// "crate": { parsed crate ... },
|
// "crate": { parsed crate ... },
|
||||||
|
@ -340,6 +347,7 @@ fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson], dst: Path) {
|
||||||
json.insert(~"crate", crate_json);
|
json.insert(~"crate", crate_json);
|
||||||
json.insert(~"plugins", json::Object(plugins_json));
|
json.insert(~"plugins", json::Object(plugins_json));
|
||||||
|
|
||||||
let mut file = File::create(&dst).unwrap();
|
let mut file = if_ok!(File::create(&dst));
|
||||||
json::Object(json).to_writer(&mut file);
|
if_ok!(json::Object(json).to_writer(&mut file));
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,8 +127,8 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>) {
|
||||||
let exe = outdir.path().join("rust_out");
|
let exe = outdir.path().join("rust_out");
|
||||||
let out = run::process_output(exe.as_str().unwrap(), []);
|
let out = run::process_output(exe.as_str().unwrap(), []);
|
||||||
match out {
|
match out {
|
||||||
None => fail!("couldn't run the test"),
|
Err(e) => fail!("couldn't run the test: {}", e),
|
||||||
Some(out) => {
|
Ok(out) => {
|
||||||
if !out.status.success() {
|
if !out.status.success() {
|
||||||
fail!("test executable failed:\n{}",
|
fail!("test executable failed:\n{}",
|
||||||
str::from_utf8(out.error));
|
str::from_utf8(out.error));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue