Make Rustdoc strip private fields
In addition, the renderer will add comments to structs and enums saying that fields or variants have been stripped.
This commit is contained in:
parent
009c3d8bae
commit
d6d31d788d
@ -685,6 +685,7 @@ pub struct Struct {
|
|||||||
struct_type: doctree::StructType,
|
struct_type: doctree::StructType,
|
||||||
generics: Generics,
|
generics: Generics,
|
||||||
fields: ~[Item],
|
fields: ~[Item],
|
||||||
|
fields_stripped: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<Item> for doctree::Struct {
|
impl Clean<Item> for doctree::Struct {
|
||||||
@ -699,6 +700,7 @@ impl Clean<Item> for doctree::Struct {
|
|||||||
struct_type: self.struct_type,
|
struct_type: self.struct_type,
|
||||||
generics: self.generics.clean(),
|
generics: self.generics.clean(),
|
||||||
fields: self.fields.clean(),
|
fields: self.fields.clean(),
|
||||||
|
fields_stripped: false,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -711,6 +713,7 @@ impl Clean<Item> for doctree::Struct {
|
|||||||
pub struct VariantStruct {
|
pub struct VariantStruct {
|
||||||
struct_type: doctree::StructType,
|
struct_type: doctree::StructType,
|
||||||
fields: ~[Item],
|
fields: ~[Item],
|
||||||
|
fields_stripped: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<VariantStruct> for syntax::ast::struct_def {
|
impl Clean<VariantStruct> for syntax::ast::struct_def {
|
||||||
@ -718,6 +721,7 @@ impl Clean<VariantStruct> for syntax::ast::struct_def {
|
|||||||
VariantStruct {
|
VariantStruct {
|
||||||
struct_type: doctree::struct_type_from_def(self),
|
struct_type: doctree::struct_type_from_def(self),
|
||||||
fields: self.fields.clean(),
|
fields: self.fields.clean(),
|
||||||
|
fields_stripped: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -726,6 +730,7 @@ impl Clean<VariantStruct> for syntax::ast::struct_def {
|
|||||||
pub struct Enum {
|
pub struct Enum {
|
||||||
variants: ~[Item],
|
variants: ~[Item],
|
||||||
generics: Generics,
|
generics: Generics,
|
||||||
|
variants_stripped: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<Item> for doctree::Enum {
|
impl Clean<Item> for doctree::Enum {
|
||||||
@ -739,6 +744,7 @@ impl Clean<Item> for doctree::Enum {
|
|||||||
inner: EnumItem(Enum {
|
inner: EnumItem(Enum {
|
||||||
variants: self.variants.clean(),
|
variants: self.variants.clean(),
|
||||||
generics: self.generics.clean(),
|
generics: self.generics.clean(),
|
||||||
|
variants_stripped: false,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,9 @@ pub trait DocFolder {
|
|||||||
StructItem(i) => {
|
StructItem(i) => {
|
||||||
let mut i = i;
|
let mut i = i;
|
||||||
let mut foo = ~[]; swap(&mut foo, &mut i.fields);
|
let mut foo = ~[]; swap(&mut foo, &mut i.fields);
|
||||||
|
let num_fields = foo.len();
|
||||||
i.fields.extend(&mut foo.move_iter().filter_map(|x| self.fold_item(x)));
|
i.fields.extend(&mut foo.move_iter().filter_map(|x| self.fold_item(x)));
|
||||||
|
i.fields_stripped |= num_fields != i.fields.len();
|
||||||
StructItem(i)
|
StructItem(i)
|
||||||
},
|
},
|
||||||
ModuleItem(i) => {
|
ModuleItem(i) => {
|
||||||
@ -36,7 +38,9 @@ pub trait DocFolder {
|
|||||||
EnumItem(i) => {
|
EnumItem(i) => {
|
||||||
let mut i = i;
|
let mut i = i;
|
||||||
let mut foo = ~[]; swap(&mut foo, &mut i.variants);
|
let mut foo = ~[]; swap(&mut foo, &mut i.variants);
|
||||||
|
let num_variants = foo.len();
|
||||||
i.variants.extend(&mut foo.move_iter().filter_map(|x| self.fold_item(x)));
|
i.variants.extend(&mut foo.move_iter().filter_map(|x| self.fold_item(x)));
|
||||||
|
i.variants_stripped |= num_variants != i.variants.len();
|
||||||
EnumItem(i)
|
EnumItem(i)
|
||||||
},
|
},
|
||||||
TraitItem(i) => {
|
TraitItem(i) => {
|
||||||
@ -73,7 +77,9 @@ pub trait DocFolder {
|
|||||||
StructVariant(j) => {
|
StructVariant(j) => {
|
||||||
let mut j = j;
|
let mut j = j;
|
||||||
let mut foo = ~[]; swap(&mut foo, &mut j.fields);
|
let mut foo = ~[]; swap(&mut foo, &mut j.fields);
|
||||||
|
let num_fields = foo.len();
|
||||||
j.fields.extend(&mut foo.move_iter().filter_map(c));
|
j.fields.extend(&mut foo.move_iter().filter_map(c));
|
||||||
|
j.fields_stripped |= num_fields != j.fields.len();
|
||||||
VariantItem(Variant {kind: StructVariant(j), ..i2})
|
VariantItem(Variant {kind: StructVariant(j), ..i2})
|
||||||
},
|
},
|
||||||
_ => VariantItem(i2)
|
_ => VariantItem(i2)
|
||||||
|
@ -1265,7 +1265,8 @@ fn render_method(w: &mut io::Writer, meth: &clean::Item, withlink: bool) {
|
|||||||
|
|
||||||
fn item_struct(w: &mut io::Writer, it: &clean::Item, s: &clean::Struct) {
|
fn item_struct(w: &mut io::Writer, it: &clean::Item, s: &clean::Struct) {
|
||||||
write!(w, "<pre class='struct'>");
|
write!(w, "<pre class='struct'>");
|
||||||
render_struct(w, it, Some(&s.generics), s.struct_type, s.fields, "", true);
|
render_struct(w, it, Some(&s.generics), s.struct_type, s.fields,
|
||||||
|
s.fields_stripped, "", true);
|
||||||
write!(w, "</pre>");
|
write!(w, "</pre>");
|
||||||
|
|
||||||
document(w, it);
|
document(w, it);
|
||||||
@ -1312,7 +1313,7 @@ fn item_enum(w: &mut io::Writer, it: &clean::Item, e: &clean::Enum) {
|
|||||||
}
|
}
|
||||||
clean::StructVariant(ref s) => {
|
clean::StructVariant(ref s) => {
|
||||||
render_struct(w, v, None, s.struct_type, s.fields,
|
render_struct(w, v, None, s.struct_type, s.fields,
|
||||||
" ", false);
|
s.fields_stripped, " ", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1320,6 +1321,10 @@ fn item_enum(w: &mut io::Writer, it: &clean::Item, e: &clean::Enum) {
|
|||||||
}
|
}
|
||||||
write!(w, ",\n");
|
write!(w, ",\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if e.variants_stripped {
|
||||||
|
write!(w, " // some variants omitted\n");
|
||||||
|
}
|
||||||
write!(w, "\\}");
|
write!(w, "\\}");
|
||||||
}
|
}
|
||||||
write!(w, "</pre>");
|
write!(w, "</pre>");
|
||||||
@ -1343,6 +1348,7 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
|
|||||||
g: Option<&clean::Generics>,
|
g: Option<&clean::Generics>,
|
||||||
ty: doctree::StructType,
|
ty: doctree::StructType,
|
||||||
fields: &[clean::Item],
|
fields: &[clean::Item],
|
||||||
|
fields_stripped: bool,
|
||||||
tab: &str,
|
tab: &str,
|
||||||
structhead: bool) {
|
structhead: bool) {
|
||||||
write!(w, "{}{}{}",
|
write!(w, "{}{}{}",
|
||||||
@ -1368,6 +1374,10 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
|
|||||||
_ => unreachable!()
|
_ => unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if fields_stripped {
|
||||||
|
write!(w, " // some fields omitted\n{}", tab);
|
||||||
|
}
|
||||||
write!(w, "\\}");
|
write!(w, "\\}");
|
||||||
}
|
}
|
||||||
doctree::Tuple | doctree::Newtype => {
|
doctree::Tuple | doctree::Newtype => {
|
||||||
|
@ -70,17 +70,13 @@ pub fn strip_private(mut crate: clean::Crate) -> plugins::PluginResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are public-by-default (if the enum was public)
|
// These are public-by-default (if the enum/struct was public)
|
||||||
clean::VariantItem(*) => {
|
clean::VariantItem(*) | clean::StructFieldItem(*) => {
|
||||||
if i.visibility == Some(ast::private) {
|
if i.visibility == Some(ast::private) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We show these regardless of whether they're public/private
|
|
||||||
// because it's useful to see sometimes
|
|
||||||
clean::StructFieldItem(*) => {}
|
|
||||||
|
|
||||||
// handled below
|
// handled below
|
||||||
clean::ModuleItem(*) => {}
|
clean::ModuleItem(*) => {}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ pub mod passes;
|
|||||||
pub mod plugins;
|
pub mod plugins;
|
||||||
pub mod visit_ast;
|
pub mod visit_ast;
|
||||||
|
|
||||||
pub static SCHEMA_VERSION: &'static str = "0.8.0";
|
pub static SCHEMA_VERSION: &'static str = "0.8.1";
|
||||||
|
|
||||||
type Pass = (&'static str, // name
|
type Pass = (&'static str, // name
|
||||||
extern fn(clean::Crate) -> plugins::PluginResult, // fn
|
extern fn(clean::Crate) -> plugins::PluginResult, // fn
|
||||||
|
Loading…
x
Reference in New Issue
Block a user