@@ -1675,11 +1675,19 @@ impl<'a> Item<'a> {
1675
1675
}
1676
1676
}
1677
1677
1678
+ fn wrap_into_docblock < F > ( w : & mut fmt:: Formatter ,
1679
+ f : F ) -> fmt:: Result
1680
+ where F : Fn ( & mut fmt:: Formatter ) -> fmt:: Result {
1681
+ write ! ( w, "<div class=\" docblock type-decl\" >" ) ?;
1682
+ f ( w) ?;
1683
+ write ! ( w, "</div>" )
1684
+ }
1685
+
1678
1686
impl < ' a > fmt:: Display for Item < ' a > {
1679
1687
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
1680
1688
debug_assert ! ( !self . item. is_stripped( ) ) ;
1681
1689
// Write the breadcrumb trail header for the top
1682
- write ! ( fmt, "\n <h1 class='fqn'><span class='in-band'>" ) ?;
1690
+ write ! ( fmt, "<h1 class='fqn'><span class='in-band'>" ) ?;
1683
1691
match self . item . inner {
1684
1692
clean:: ModuleItem ( ref m) => if m. is_crate {
1685
1693
write ! ( fmt, "Crate " ) ?;
@@ -1741,14 +1749,11 @@ impl<'a> fmt::Display for Item<'a> {
1741
1749
}
1742
1750
}
1743
1751
1744
- write ! ( fmt, "</span>" ) ?; // out-of-band
1745
-
1746
- write ! ( fmt, "</h1>\n " ) ?;
1752
+ write ! ( fmt, "</span></h1>" ) ?; // out-of-band
1747
1753
1748
1754
match self . item . inner {
1749
- clean:: ModuleItem ( ref m) => {
1750
- item_module ( fmt, self . cx , self . item , & m. items )
1751
- }
1755
+ clean:: ModuleItem ( ref m) =>
1756
+ item_module ( fmt, self . cx , self . item , & m. items ) ,
1752
1757
clean:: FunctionItem ( ref f) | clean:: ForeignFunctionItem ( ref f) =>
1753
1758
item_function ( fmt, self . cx , self . item , f) ,
1754
1759
clean:: TraitItem ( ref t) => item_trait ( fmt, self . cx , self . item , t) ,
@@ -2306,79 +2311,81 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2306
2311
}
2307
2312
}
2308
2313
2309
- // Output the trait definition
2310
- write ! ( w, "<pre class='rust trait'>" ) ?;
2311
- render_attributes ( w, it) ?;
2312
- write ! ( w, "{}{}{}trait {}{}{}" ,
2313
- VisSpace ( & it. visibility) ,
2314
- UnsafetySpace ( t. unsafety) ,
2315
- if t. is_auto { "auto " } else { "" } ,
2316
- it. name. as_ref( ) . unwrap( ) ,
2317
- t. generics,
2318
- bounds) ?;
2319
-
2320
- if !t. generics . where_predicates . is_empty ( ) {
2321
- write ! ( w, "{}" , WhereClause { gens: & t. generics, indent: 0 , end_newline: true } ) ?;
2322
- } else {
2323
- write ! ( w, " " ) ?;
2324
- }
2325
-
2326
2314
let types = t. items . iter ( ) . filter ( |m| m. is_associated_type ( ) ) . collect :: < Vec < _ > > ( ) ;
2327
2315
let consts = t. items . iter ( ) . filter ( |m| m. is_associated_const ( ) ) . collect :: < Vec < _ > > ( ) ;
2328
2316
let required = t. items . iter ( ) . filter ( |m| m. is_ty_method ( ) ) . collect :: < Vec < _ > > ( ) ;
2329
2317
let provided = t. items . iter ( ) . filter ( |m| m. is_method ( ) ) . collect :: < Vec < _ > > ( ) ;
2330
2318
2331
- if t. items . is_empty ( ) {
2332
- write ! ( w, "{{ }}" ) ?;
2333
- } else {
2334
- // FIXME: we should be using a derived_id for the Anchors here
2335
- write ! ( w, "{{\n " ) ?;
2336
- for t in & types {
2337
- write ! ( w, " " ) ?;
2338
- render_assoc_item ( w, t, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2339
- write ! ( w, ";\n " ) ?;
2340
- }
2341
- if !types. is_empty ( ) && !consts. is_empty ( ) {
2342
- w. write_str ( "\n " ) ?;
2343
- }
2344
- for t in & consts {
2345
- write ! ( w, " " ) ?;
2346
- render_assoc_item ( w, t, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2347
- write ! ( w, ";\n " ) ?;
2348
- }
2349
- if !consts. is_empty ( ) && !required. is_empty ( ) {
2350
- w. write_str ( "\n " ) ?;
2319
+ // Output the trait definition
2320
+ wrap_into_docblock ( w, |w| {
2321
+ write ! ( w, "<pre class='rust trait'>" ) ?;
2322
+ render_attributes ( w, it) ?;
2323
+ write ! ( w, "{}{}{}trait {}{}{}" ,
2324
+ VisSpace ( & it. visibility) ,
2325
+ UnsafetySpace ( t. unsafety) ,
2326
+ if t. is_auto { "auto " } else { "" } ,
2327
+ it. name. as_ref( ) . unwrap( ) ,
2328
+ t. generics,
2329
+ bounds) ?;
2330
+
2331
+ if !t. generics . where_predicates . is_empty ( ) {
2332
+ write ! ( w, "{}" , WhereClause { gens: & t. generics, indent: 0 , end_newline: true } ) ?;
2333
+ } else {
2334
+ write ! ( w, " " ) ?;
2351
2335
}
2352
- for ( pos, m) in required. iter ( ) . enumerate ( ) {
2353
- write ! ( w, " " ) ?;
2354
- render_assoc_item ( w, m, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2355
- write ! ( w, ";\n " ) ?;
2356
2336
2357
- if pos < required. len ( ) - 1 {
2358
- write ! ( w, "<div class='item-spacer'></div>" ) ?;
2337
+ if t. items . is_empty ( ) {
2338
+ write ! ( w, "{{ }}" ) ?;
2339
+ } else {
2340
+ // FIXME: we should be using a derived_id for the Anchors here
2341
+ write ! ( w, "{{\n " ) ?;
2342
+ for t in & types {
2343
+ write ! ( w, " " ) ?;
2344
+ render_assoc_item ( w, t, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2345
+ write ! ( w, ";\n " ) ?;
2359
2346
}
2360
- }
2361
- if !required. is_empty ( ) && !provided. is_empty ( ) {
2362
- w. write_str ( "\n " ) ?;
2363
- }
2364
- for ( pos, m) in provided. iter ( ) . enumerate ( ) {
2365
- write ! ( w, " " ) ?;
2366
- render_assoc_item ( w, m, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2367
- match m. inner {
2368
- clean:: MethodItem ( ref inner) if !inner. generics . where_predicates . is_empty ( ) => {
2369
- write ! ( w, ",\n {{ ... }}\n " ) ?;
2370
- } ,
2371
- _ => {
2372
- write ! ( w, " {{ ... }}\n " ) ?;
2373
- } ,
2347
+ if !types. is_empty ( ) && !consts. is_empty ( ) {
2348
+ w. write_str ( "\n " ) ?;
2374
2349
}
2375
- if pos < provided. len ( ) - 1 {
2376
- write ! ( w, "<div class='item-spacer'></div>" ) ?;
2350
+ for t in & consts {
2351
+ write ! ( w, " " ) ?;
2352
+ render_assoc_item ( w, t, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2353
+ write ! ( w, ";\n " ) ?;
2377
2354
}
2355
+ if !consts. is_empty ( ) && !required. is_empty ( ) {
2356
+ w. write_str ( "\n " ) ?;
2357
+ }
2358
+ for ( pos, m) in required. iter ( ) . enumerate ( ) {
2359
+ write ! ( w, " " ) ?;
2360
+ render_assoc_item ( w, m, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2361
+ write ! ( w, ";\n " ) ?;
2362
+
2363
+ if pos < required. len ( ) - 1 {
2364
+ write ! ( w, "<div class='item-spacer'></div>" ) ?;
2365
+ }
2366
+ }
2367
+ if !required. is_empty ( ) && !provided. is_empty ( ) {
2368
+ w. write_str ( "\n " ) ?;
2369
+ }
2370
+ for ( pos, m) in provided. iter ( ) . enumerate ( ) {
2371
+ write ! ( w, " " ) ?;
2372
+ render_assoc_item ( w, m, AssocItemLink :: Anchor ( None ) , ItemType :: Trait ) ?;
2373
+ match m. inner {
2374
+ clean:: MethodItem ( ref inner) if !inner. generics . where_predicates . is_empty ( ) => {
2375
+ write ! ( w, ",\n {{ ... }}\n " ) ?;
2376
+ } ,
2377
+ _ => {
2378
+ write ! ( w, " {{ ... }}\n " ) ?;
2379
+ } ,
2380
+ }
2381
+ if pos < provided. len ( ) - 1 {
2382
+ write ! ( w, "<div class='item-spacer'></div>" ) ?;
2383
+ }
2384
+ }
2385
+ write ! ( w, "}}" ) ?;
2378
2386
}
2379
- write ! ( w, "}}" ) ?;
2380
- }
2381
- write ! ( w, "</pre>" ) ?;
2387
+ write ! ( w, "</pre>" )
2388
+ } ) ?;
2382
2389
2383
2390
// Trait documentation
2384
2391
document ( w, cx, it) ?;
@@ -2717,16 +2724,18 @@ fn render_assoc_item(w: &mut fmt::Formatter,
2717
2724
2718
2725
fn item_struct ( w : & mut fmt:: Formatter , cx : & Context , it : & clean:: Item ,
2719
2726
s : & clean:: Struct ) -> fmt:: Result {
2720
- write ! ( w, "<pre class='rust struct'>" ) ?;
2721
- render_attributes ( w, it) ?;
2722
- render_struct ( w,
2723
- it,
2724
- Some ( & s. generics ) ,
2725
- s. struct_type ,
2726
- & s. fields ,
2727
- "" ,
2728
- true ) ?;
2729
- write ! ( w, "</pre>" ) ?;
2727
+ wrap_into_docblock ( w, |w| {
2728
+ write ! ( w, "<pre class='rust struct'>" ) ?;
2729
+ render_attributes ( w, it) ?;
2730
+ render_struct ( w,
2731
+ it,
2732
+ Some ( & s. generics ) ,
2733
+ s. struct_type ,
2734
+ & s. fields ,
2735
+ "" ,
2736
+ true ) ?;
2737
+ write ! ( w, "</pre>" )
2738
+ } ) ?;
2730
2739
2731
2740
document ( w, cx, it) ?;
2732
2741
let mut fields = s. fields . iter ( ) . filter_map ( |f| {
@@ -2769,15 +2778,17 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2769
2778
2770
2779
fn item_union ( w : & mut fmt:: Formatter , cx : & Context , it : & clean:: Item ,
2771
2780
s : & clean:: Union ) -> fmt:: Result {
2772
- write ! ( w, "<pre class='rust union'>" ) ?;
2773
- render_attributes ( w, it) ?;
2774
- render_union ( w,
2775
- it,
2776
- Some ( & s. generics ) ,
2777
- & s. fields ,
2778
- "" ,
2779
- true ) ?;
2780
- write ! ( w, "</pre>" ) ?;
2781
+ wrap_into_docblock ( w, |w| {
2782
+ write ! ( w, "<pre class='rust union'>" ) ?;
2783
+ render_attributes ( w, it) ?;
2784
+ render_union ( w,
2785
+ it,
2786
+ Some ( & s. generics ) ,
2787
+ & s. fields ,
2788
+ "" ,
2789
+ true ) ?;
2790
+ write ! ( w, "</pre>" )
2791
+ } ) ?;
2781
2792
2782
2793
document ( w, cx, it) ?;
2783
2794
let mut fields = s. fields . iter ( ) . filter_map ( |f| {
@@ -2807,56 +2818,58 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2807
2818
2808
2819
fn item_enum ( w : & mut fmt:: Formatter , cx : & Context , it : & clean:: Item ,
2809
2820
e : & clean:: Enum ) -> fmt:: Result {
2810
- write ! ( w, "<pre class='rust enum'>" ) ?;
2811
- render_attributes ( w, it) ?;
2812
- write ! ( w, "{}enum {}{}{}" ,
2813
- VisSpace ( & it. visibility) ,
2814
- it. name. as_ref( ) . unwrap( ) ,
2815
- e. generics,
2816
- WhereClause { gens: & e. generics, indent: 0 , end_newline: true } ) ?;
2817
- if e. variants . is_empty ( ) && !e. variants_stripped {
2818
- write ! ( w, " {{}}" ) ?;
2819
- } else {
2820
- write ! ( w, " {{\n " ) ?;
2821
- for v in & e. variants {
2822
- write ! ( w, " " ) ?;
2823
- let name = v. name . as_ref ( ) . unwrap ( ) ;
2824
- match v. inner {
2825
- clean:: VariantItem ( ref var) => {
2826
- match var. kind {
2827
- clean:: VariantKind :: CLike => write ! ( w, "{}" , name) ?,
2828
- clean:: VariantKind :: Tuple ( ref tys) => {
2829
- write ! ( w, "{}(" , name) ?;
2830
- for ( i, ty) in tys. iter ( ) . enumerate ( ) {
2831
- if i > 0 {
2832
- write ! ( w, ", " ) ?
2821
+ wrap_into_docblock ( w, |w| {
2822
+ write ! ( w, "<pre class='rust enum'>" ) ?;
2823
+ render_attributes ( w, it) ?;
2824
+ write ! ( w, "{}enum {}{}{}" ,
2825
+ VisSpace ( & it. visibility) ,
2826
+ it. name. as_ref( ) . unwrap( ) ,
2827
+ e. generics,
2828
+ WhereClause { gens: & e. generics, indent: 0 , end_newline: true } ) ?;
2829
+ if e. variants . is_empty ( ) && !e. variants_stripped {
2830
+ write ! ( w, " {{}}" ) ?;
2831
+ } else {
2832
+ write ! ( w, " {{\n " ) ?;
2833
+ for v in & e. variants {
2834
+ write ! ( w, " " ) ?;
2835
+ let name = v. name . as_ref ( ) . unwrap ( ) ;
2836
+ match v. inner {
2837
+ clean:: VariantItem ( ref var) => {
2838
+ match var. kind {
2839
+ clean:: VariantKind :: CLike => write ! ( w, "{}" , name) ?,
2840
+ clean:: VariantKind :: Tuple ( ref tys) => {
2841
+ write ! ( w, "{}(" , name) ?;
2842
+ for ( i, ty) in tys. iter ( ) . enumerate ( ) {
2843
+ if i > 0 {
2844
+ write ! ( w, ", " ) ?
2845
+ }
2846
+ write ! ( w, "{}" , * ty) ?;
2833
2847
}
2834
- write ! ( w, "{}" , * ty) ?;
2848
+ write ! ( w, ")" ) ?;
2849
+ }
2850
+ clean:: VariantKind :: Struct ( ref s) => {
2851
+ render_struct ( w,
2852
+ v,
2853
+ None ,
2854
+ s. struct_type ,
2855
+ & s. fields ,
2856
+ " " ,
2857
+ false ) ?;
2835
2858
}
2836
- write ! ( w, ")" ) ?;
2837
- }
2838
- clean:: VariantKind :: Struct ( ref s) => {
2839
- render_struct ( w,
2840
- v,
2841
- None ,
2842
- s. struct_type ,
2843
- & s. fields ,
2844
- " " ,
2845
- false ) ?;
2846
2859
}
2847
2860
}
2861
+ _ => unreachable ! ( )
2848
2862
}
2849
- _ => unreachable ! ( )
2863
+ write ! ( w , ", \n " ) ? ;
2850
2864
}
2851
- write ! ( w, ",\n " ) ?;
2852
- }
2853
2865
2854
- if e. variants_stripped {
2855
- write ! ( w, " // some variants omitted\n " ) ?;
2866
+ if e. variants_stripped {
2867
+ write ! ( w, " // some variants omitted\n " ) ?;
2868
+ }
2869
+ write ! ( w, "}}" ) ?;
2856
2870
}
2857
- write ! ( w, "}}" ) ?;
2858
- }
2859
- write ! ( w, "</pre>" ) ?;
2871
+ write ! ( w, "</pre>" )
2872
+ } ) ?;
2860
2873
2861
2874
document ( w, cx, it) ?;
2862
2875
if !e. variants . is_empty ( ) {
@@ -4044,11 +4057,13 @@ impl<'a> fmt::Display for Source<'a> {
4044
4057
4045
4058
fn item_macro ( w : & mut fmt:: Formatter , cx : & Context , it : & clean:: Item ,
4046
4059
t : & clean:: Macro ) -> fmt:: Result {
4047
- w. write_str ( & highlight:: render_with_highlighting ( & t. source ,
4048
- Some ( "macro" ) ,
4049
- None ,
4050
- None ,
4051
- None ) ) ?;
4060
+ wrap_into_docblock ( w, |w| {
4061
+ w. write_str ( & highlight:: render_with_highlighting ( & t. source ,
4062
+ Some ( "macro" ) ,
4063
+ None ,
4064
+ None ,
4065
+ None ) )
4066
+ } ) ?;
4052
4067
document ( w, cx, it)
4053
4068
}
4054
4069
0 commit comments