@@ -1631,54 +1631,49 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
1631
1631
} )
1632
1632
}
1633
1633
1634
- fn render_fields < ' b > ( & ' b self ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1634
+ fn fields ( & self ) -> impl Iterator < Item = ( & clean:: Item , & clean:: Type ) > {
1635
+ self . s . fields . iter ( ) . filter_map ( |item| match * item. kind {
1636
+ clean:: StructFieldItem ( ref ty) => Some ( ( item, ty) ) ,
1637
+ _ => None ,
1638
+ } )
1639
+ }
1640
+
1641
+ fn should_render_fields ( & self ) -> bool {
1642
+ matches ! ( self . s. ctor_kind, None | Some ( CtorKind :: Fn ) )
1643
+ && self . fields ( ) . peekable ( ) . peek ( ) . is_some ( )
1644
+ }
1645
+
1646
+ fn document_non_exhaustive_header ( & self ) -> & str {
1647
+ document_non_exhaustive_header ( self . it )
1648
+ }
1649
+
1650
+ fn document_non_exhaustive ( & self ) -> impl fmt:: Display + ' a {
1651
+ document_non_exhaustive ( self . it )
1652
+ }
1653
+
1654
+ fn render_field < ' b > (
1655
+ & ' b self ,
1656
+ index : & ' b usize ,
1657
+ field : & ' b clean:: Item ,
1658
+ ty : & ' b clean:: Type ,
1659
+ ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1635
1660
display_fn ( move |f| {
1636
- let mut fields = self
1637
- . s
1638
- . fields
1639
- . iter ( )
1640
- . filter_map ( |f| match * f. kind {
1641
- clean:: StructFieldItem ( ref ty) => Some ( ( f, ty) ) ,
1642
- _ => None ,
1643
- } )
1644
- . peekable ( ) ;
1645
- if let None | Some ( CtorKind :: Fn ) = self . s . ctor_kind {
1646
- if fields. peek ( ) . is_some ( ) {
1647
- write ! (
1648
- f,
1649
- "<h2 id=\" fields\" class=\" fields small-section-header\" >\
1650
- {}{}<a href=\" #fields\" class=\" anchor\" >§</a>\
1651
- </h2>\
1652
- {}",
1653
- if self . s. ctor_kind. is_none( ) { "Fields" } else { "Tuple Fields" } ,
1654
- document_non_exhaustive_header( self . it) ,
1655
- document_non_exhaustive( self . it)
1656
- ) ?;
1657
- let mut cx = self . cx . borrow_mut ( ) ;
1658
- for ( index, ( field, ty) ) in fields. enumerate ( ) {
1659
- let field_name = field
1660
- . name
1661
- . map_or_else ( || index. to_string ( ) , |sym| sym. as_str ( ) . to_string ( ) ) ;
1662
- let id =
1663
- cx. derive_id ( format ! ( "{}.{}" , ItemType :: StructField , field_name) ) ;
1664
- write ! (
1665
- f,
1666
- "<span id=\" {id}\" class=\" {item_type} small-section-header\" >\
1667
- <a href=\" #{id}\" class=\" anchor field\" >§</a>\
1668
- <code>{field_name}: {ty}</code>\
1669
- </span>",
1670
- ty = ty. print( * cx) ,
1671
- item_type = ItemType :: StructField ,
1672
- ) ?;
1673
- write ! (
1674
- f,
1675
- "{doc}" ,
1676
- doc = document( * cx, field, Some ( self . it) , HeadingOffset :: H3 ) ,
1677
- ) ?;
1678
- }
1679
- }
1680
- }
1681
- Ok ( ( ) )
1661
+ let mut cx = self . cx . borrow_mut ( ) ;
1662
+ let field_name =
1663
+ field. name . map_or_else ( || index. to_string ( ) , |sym| sym. as_str ( ) . to_string ( ) ) ;
1664
+ let id = cx. derive_id ( format ! ( "{}.{}" , ItemType :: StructField , field_name) ) ;
1665
+ write ! (
1666
+ f,
1667
+ "<span id=\" {id}\" class=\" {item_type} small-section-header\" >\
1668
+ <a href=\" #{id}\" class=\" anchor field\" >§</a>\
1669
+ <code>{field_name}: {ty}</code>\
1670
+ </span>",
1671
+ ty = ty. print( * cx) ,
1672
+ item_type = ItemType :: StructField ,
1673
+ ) ?;
1674
+
1675
+ let v = document ( * cx, field, Some ( self . it ) , HeadingOffset :: H3 ) ;
1676
+ write ! ( f, "{v}" )
1682
1677
} )
1683
1678
}
1684
1679
0 commit comments