@@ -1853,54 +1853,49 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
18531853 } )
18541854 }
18551855
1856- fn render_fields < ' b > ( & ' b self ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1856+ fn fields ( & self ) -> impl Iterator < Item = ( & clean:: Item , & clean:: Type ) > {
1857+ self . s . fields . iter ( ) . filter_map ( |item| match * item. kind {
1858+ clean:: StructFieldItem ( ref ty) => Some ( ( item, ty) ) ,
1859+ _ => None ,
1860+ } )
1861+ }
1862+
1863+ fn should_render_fields ( & self ) -> bool {
1864+ matches ! ( self . s. ctor_kind, None | Some ( CtorKind :: Fn ) )
1865+ && self . fields ( ) . peekable ( ) . peek ( ) . is_some ( )
1866+ }
1867+
1868+ fn document_non_exhaustive_header ( & self ) -> & str {
1869+ document_non_exhaustive_header ( self . it )
1870+ }
1871+
1872+ fn document_non_exhaustive ( & self ) -> impl fmt:: Display + ' a {
1873+ document_non_exhaustive ( self . it )
1874+ }
1875+
1876+ fn render_field < ' b > (
1877+ & ' b self ,
1878+ index : & ' b usize ,
1879+ field : & ' b clean:: Item ,
1880+ ty : & ' b clean:: Type ,
1881+ ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
18571882 display_fn ( move |f| {
1858- let mut fields = self
1859- . s
1860- . fields
1861- . iter ( )
1862- . filter_map ( |f| match * f. kind {
1863- clean:: StructFieldItem ( ref ty) => Some ( ( f, ty) ) ,
1864- _ => None ,
1865- } )
1866- . peekable ( ) ;
1867- if let None | Some ( CtorKind :: Fn ) = self . s . ctor_kind {
1868- if fields. peek ( ) . is_some ( ) {
1869- write ! (
1870- f,
1871- "<h2 id=\" fields\" class=\" fields small-section-header\" >\
1872- {}{}<a href=\" #fields\" class=\" anchor\" >§</a>\
1873- </h2>\
1874- {}",
1875- if self . s. ctor_kind. is_none( ) { "Fields" } else { "Tuple Fields" } ,
1876- document_non_exhaustive_header( self . it) ,
1877- document_non_exhaustive( self . it)
1878- ) ?;
1879- let mut cx = self . cx . borrow_mut ( ) ;
1880- for ( index, ( field, ty) ) in fields. enumerate ( ) {
1881- let field_name = field
1882- . name
1883- . map_or_else ( || index. to_string ( ) , |sym| sym. as_str ( ) . to_string ( ) ) ;
1884- let id =
1885- cx. derive_id ( format ! ( "{}.{}" , ItemType :: StructField , field_name) ) ;
1886- write ! (
1887- f,
1888- "<span id=\" {id}\" class=\" {item_type} small-section-header\" >\
1889- <a href=\" #{id}\" class=\" anchor field\" >§</a>\
1890- <code>{field_name}: {ty}</code>\
1891- </span>",
1892- ty = ty. print( * cx) ,
1893- item_type = ItemType :: StructField ,
1894- ) ?;
1895- write ! (
1896- f,
1897- "{doc}" ,
1898- doc = document( * cx, field, Some ( self . it) , HeadingOffset :: H3 ) ,
1899- ) ?;
1900- }
1901- }
1902- }
1903- Ok ( ( ) )
1883+ let mut cx = self . cx . borrow_mut ( ) ;
1884+ let field_name =
1885+ field. name . map_or_else ( || index. to_string ( ) , |sym| sym. as_str ( ) . to_string ( ) ) ;
1886+ let id = cx. derive_id ( format ! ( "{}.{}" , ItemType :: StructField , field_name) ) ;
1887+ write ! (
1888+ f,
1889+ "<span id=\" {id}\" class=\" {item_type} small-section-header\" >\
1890+ <a href=\" #{id}\" class=\" anchor field\" >§</a>\
1891+ <code>{field_name}: {ty}</code>\
1892+ </span>",
1893+ ty = ty. print( * cx) ,
1894+ item_type = ItemType :: StructField ,
1895+ ) ?;
1896+
1897+ let v = document ( * cx, field, Some ( self . it ) , HeadingOffset :: H3 ) ;
1898+ write ! ( f, "{v}" )
19041899 } )
19051900 }
19061901
0 commit comments