@@ -28,6 +28,7 @@ use extra::json::ToJson;
28
28
use extra:: sort;
29
29
30
30
use syntax:: ast;
31
+ use syntax:: attr;
31
32
32
33
use clean;
33
34
use doctree;
@@ -521,6 +522,14 @@ impl Context {
521
522
}
522
523
}
523
524
}
525
+ clean:: StructItem ( s) => {
526
+ let mut it = s. fields . move_iter ( ) ;
527
+ do self. recurse ( name) |this| {
528
+ for item in it {
529
+ f ( this, item) ;
530
+ }
531
+ }
532
+ }
524
533
_ => { }
525
534
}
526
535
}
@@ -532,19 +541,21 @@ impl Context {
532
541
533
542
fn shortty ( item : & clean:: Item ) -> & ' static str {
534
543
match item. inner {
535
- clean:: ModuleItem ( * ) => "mod" ,
536
- clean:: StructItem ( * ) => "struct" ,
537
- clean:: EnumItem ( * ) => "enum" ,
538
- clean:: FunctionItem ( * ) => "fn" ,
539
- clean:: TypedefItem ( * ) => "typedef" ,
540
- clean:: StaticItem ( * ) => "static" ,
541
- clean:: TraitItem ( * ) => "trait" ,
542
- clean:: ImplItem ( * ) => "impl" ,
543
- clean:: ViewItemItem ( * ) => "viewitem" ,
544
- clean:: TyMethodItem ( * ) => "tymethod" ,
545
- clean:: MethodItem ( * ) => "method" ,
546
- clean:: StructFieldItem ( * ) => "structfield" ,
547
- clean:: VariantItem ( * ) => "variant" ,
544
+ clean:: ModuleItem ( * ) => "mod" ,
545
+ clean:: StructItem ( * ) => "struct" ,
546
+ clean:: EnumItem ( * ) => "enum" ,
547
+ clean:: FunctionItem ( * ) => "fn" ,
548
+ clean:: TypedefItem ( * ) => "typedef" ,
549
+ clean:: StaticItem ( * ) => "static" ,
550
+ clean:: TraitItem ( * ) => "trait" ,
551
+ clean:: ImplItem ( * ) => "impl" ,
552
+ clean:: ViewItemItem ( * ) => "viewitem" ,
553
+ clean:: TyMethodItem ( * ) => "tymethod" ,
554
+ clean:: MethodItem ( * ) => "method" ,
555
+ clean:: StructFieldItem ( * ) => "structfield" ,
556
+ clean:: VariantItem ( * ) => "variant" ,
557
+ clean:: ForeignFunctionItem ( * ) => "ffi" ,
558
+ clean:: ForeignStaticItem ( * ) => "ffs" ,
548
559
}
549
560
}
550
561
@@ -558,6 +569,18 @@ impl<'self> Item<'self> {
558
569
559
570
impl < ' self > fmt:: Default for Item < ' self > {
560
571
fn fmt ( it : & Item < ' self > , fmt : & mut fmt:: Formatter ) {
572
+ match attr:: find_stability ( it. item . attrs . iter ( ) ) {
573
+ Some ( stability) => {
574
+ write ! ( fmt. buf,
575
+ "<a class='stability {lvl}' title='{reason}'>{lvl}</a>" ,
576
+ lvl = stability. level. to_str( ) ,
577
+ reason = match stability. text {
578
+ Some ( s) => s, None => @"" ,
579
+ } ) ;
580
+ }
581
+ None => { }
582
+ }
583
+
561
584
// Write the breadcrumb trail header for the top
562
585
write ! ( fmt. buf, "<h1 class='fqn'>" ) ;
563
586
match it. item . inner {
@@ -584,12 +607,15 @@ impl<'self> fmt::Default for Item<'self> {
584
607
match it. item . inner {
585
608
clean:: ModuleItem ( ref m) => item_module ( fmt. buf , it. cx ,
586
609
it. item , m. items ) ,
587
- clean:: FunctionItem ( ref f) => item_function ( fmt. buf , it. item , f) ,
610
+ clean:: FunctionItem ( ref f) | clean:: ForeignFunctionItem ( ref f) =>
611
+ item_function ( fmt. buf , it. item , f) ,
588
612
clean:: TraitItem ( ref t) => item_trait ( fmt. buf , it. item , t) ,
589
613
clean:: StructItem ( ref s) => item_struct ( fmt. buf , it. item , s) ,
590
614
clean:: EnumItem ( ref e) => item_enum ( fmt. buf , it. item , e) ,
591
615
clean:: TypedefItem ( ref t) => item_typedef ( fmt. buf , it. item , t) ,
592
616
clean:: VariantItem ( * ) => item_variant ( fmt. buf , it. cx , it. item ) ,
617
+ clean:: StructFieldItem ( * ) => item_struct_field ( fmt. buf , it. cx ,
618
+ it. item ) ,
593
619
_ => { }
594
620
}
595
621
}
@@ -663,6 +689,10 @@ fn item_module(w: &mut io::Writer, cx: &Context,
663
689
( _, & clean:: EnumItem ( * ) ) => false ,
664
690
( & clean:: StaticItem ( * ) , _) => true ,
665
691
( _, & clean:: StaticItem ( * ) ) => false ,
692
+ ( & clean:: ForeignFunctionItem ( * ) , _) => true ,
693
+ ( _, & clean:: ForeignFunctionItem ( * ) ) => false ,
694
+ ( & clean:: ForeignStaticItem ( * ) , _) => true ,
695
+ ( _, & clean:: ForeignStaticItem ( * ) ) => false ,
666
696
( & clean:: TraitItem ( * ) , _) => true ,
667
697
( _, & clean:: TraitItem ( * ) ) => false ,
668
698
( & clean:: FunctionItem ( * ) , _) => true ,
@@ -690,27 +720,31 @@ fn item_module(w: &mut io::Writer, cx: &Context,
690
720
}
691
721
curty = myty;
692
722
write ! ( w, "<h2>{}</h2>\n <table>" , match myitem. inner {
693
- clean:: ModuleItem ( * ) => "Modules" ,
694
- clean:: StructItem ( * ) => "Structs" ,
695
- clean:: EnumItem ( * ) => "Enums" ,
696
- clean:: FunctionItem ( * ) => "Functions" ,
697
- clean:: TypedefItem ( * ) => "Type Definitions" ,
698
- clean:: StaticItem ( * ) => "Statics" ,
699
- clean:: TraitItem ( * ) => "Traits" ,
700
- clean:: ImplItem ( * ) => "Implementations" ,
701
- clean:: ViewItemItem ( * ) => "Reexports" ,
702
- clean:: TyMethodItem ( * ) => "Type Methods" ,
703
- clean:: MethodItem ( * ) => "Methods" ,
704
- clean:: StructFieldItem ( * ) => "Struct Fields" ,
705
- clean:: VariantItem ( * ) => "Variants" ,
723
+ clean:: ModuleItem ( * ) => "Modules" ,
724
+ clean:: StructItem ( * ) => "Structs" ,
725
+ clean:: EnumItem ( * ) => "Enums" ,
726
+ clean:: FunctionItem ( * ) => "Functions" ,
727
+ clean:: TypedefItem ( * ) => "Type Definitions" ,
728
+ clean:: StaticItem ( * ) => "Statics" ,
729
+ clean:: TraitItem ( * ) => "Traits" ,
730
+ clean:: ImplItem ( * ) => "Implementations" ,
731
+ clean:: ViewItemItem ( * ) => "Reexports" ,
732
+ clean:: TyMethodItem ( * ) => "Type Methods" ,
733
+ clean:: MethodItem ( * ) => "Methods" ,
734
+ clean:: StructFieldItem ( * ) => "Struct Fields" ,
735
+ clean:: VariantItem ( * ) => "Variants" ,
736
+ clean:: ForeignFunctionItem ( * ) => "Foreign Functions" ,
737
+ clean:: ForeignStaticItem ( * ) => "Foreign Statics" ,
706
738
} ) ;
707
739
}
708
740
709
741
match myitem. inner {
710
- clean:: StaticItem ( ref s) => {
742
+ clean:: StaticItem ( ref s) | clean :: ForeignStaticItem ( ref s ) => {
711
743
struct Initializer < ' self > ( & ' self str ) ;
712
744
impl < ' self > fmt:: Default for Initializer < ' self > {
713
745
fn fmt ( s : & Initializer < ' self > , f : & mut fmt:: Formatter ) {
746
+ if s. len ( ) == 0 { return ; }
747
+ write ! ( f. buf, "<code> = </code>" ) ;
714
748
let tag = if s. contains ( "\n " ) { "pre" } else { "code" } ;
715
749
write ! ( f. buf, "<{tag}>{}</{tag}>" ,
716
750
s. as_slice( ) , tag=tag) ;
@@ -719,7 +753,7 @@ fn item_module(w: &mut io::Writer, cx: &Context,
719
753
720
754
write ! ( w, "
721
755
<tr>
722
- <td><code>{}static {}: {} = </code>{}</td>
756
+ <td><code>{}static {}: {}</code>{}</td>
723
757
<td class='docblock'>{} </td>
724
758
</tr>
725
759
" ,
@@ -980,11 +1014,12 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
980
1014
for field in fields. iter ( ) {
981
1015
match field. inner {
982
1016
clean:: StructFieldItem ( ref ty) => {
983
- write ! ( w, " {}{}: {},\n {}" ,
1017
+ write ! ( w, " {}<a name='field.{name}'>{name}</a>: \
1018
+ {},\n {}",
984
1019
VisSpace ( field. visibility) ,
985
- field. name. get_ref( ) . as_slice( ) ,
986
1020
ty. type_,
987
- tab) ;
1021
+ tab,
1022
+ name = field. name. get_ref( ) . as_slice( ) ) ;
988
1023
}
989
1024
_ => unreachable ! ( )
990
1025
}
@@ -1170,3 +1205,12 @@ fn item_variant(w: &mut io::Writer, cx: &Context, it: &clean::Item) {
1170
1205
* cx. current. last( ) ,
1171
1206
it. name. get_ref( ) . as_slice( ) ) ;
1172
1207
}
1208
+
1209
+ fn item_struct_field ( w : & mut io:: Writer , cx : & Context , it : & clean:: Item ) {
1210
+ write ! ( w, "<DOCTYPE html><html><head>\
1211
+ <meta http-equiv='refresh' content='0; \
1212
+ url=../struct.{}.html\\ #field.{}'>\
1213
+ </head><body></body></html>",
1214
+ * cx. current. last( ) ,
1215
+ it. name. get_ref( ) . as_slice( ) ) ;
1216
+ }
0 commit comments