@@ -1817,9 +1817,20 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
18171817 cx : std:: cell:: RefCell < & ' a mut Context < ' cx > > ,
18181818 it : & ' a clean:: Item ,
18191819 s : & ' a clean:: Struct ,
1820+ should_render_fields : bool ,
18201821 }
18211822
18221823 impl < ' a , ' cx : ' a > ItemStruct < ' a , ' cx > {
1824+ fn new (
1825+ cx : std:: cell:: RefCell < & ' a mut Context < ' cx > > ,
1826+ it : & ' a clean:: Item ,
1827+ s : & ' a clean:: Struct ,
1828+ ) -> Self {
1829+ let should_render_fields = matches ! ( s. ctor_kind, None | Some ( CtorKind :: Fn ) )
1830+ && struct_field_items ( s) . peekable ( ) . peek ( ) . is_some ( ) ;
1831+ Self { cx, it, s, should_render_fields }
1832+ }
1833+
18231834 fn render_struct < ' b > ( & ' b self ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
18241835 display_fn ( move |f| {
18251836 let cx = self . cx . borrow ( ) ;
@@ -1844,18 +1855,6 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
18441855 } )
18451856 }
18461857
1847- fn fields ( & self ) -> impl Iterator < Item = ( & clean:: Item , & clean:: Type ) > {
1848- self . s . fields . iter ( ) . filter_map ( |item| match * item. kind {
1849- clean:: StructFieldItem ( ref ty) => Some ( ( item, ty) ) ,
1850- _ => None ,
1851- } )
1852- }
1853-
1854- fn should_render_fields ( & self ) -> bool {
1855- matches ! ( self . s. ctor_kind, None | Some ( CtorKind :: Fn ) )
1856- && self . fields ( ) . peekable ( ) . peek ( ) . is_some ( )
1857- }
1858-
18591858 fn render_field_in_span < ' b > (
18601859 & ' b self ,
18611860 index : & ' b usize ,
@@ -1913,7 +1912,14 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
19131912 }
19141913 }
19151914
1916- ItemStruct { cx : std:: cell:: RefCell :: new ( cx) , it, s } . render_into ( w) . unwrap ( ) ;
1915+ ItemStruct :: new ( std:: cell:: RefCell :: new ( cx) , it, s) . render_into ( w) . unwrap ( ) ;
1916+ }
1917+
1918+ fn struct_field_items ( s : & clean:: Struct ) -> impl Iterator < Item = ( & clean:: Item , & clean:: Type ) > {
1919+ s. fields . iter ( ) . filter_map ( |item| match * item. kind {
1920+ clean:: StructFieldItem ( ref ty) => Some ( ( item, ty) ) ,
1921+ _ => None ,
1922+ } )
19171923}
19181924
19191925fn item_static ( w : & mut impl fmt:: Write , cx : & mut Context < ' _ > , it : & clean:: Item , s : & clean:: Static ) {
0 commit comments