@@ -1817,9 +1817,20 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
1817
1817
cx : std:: cell:: RefCell < & ' a mut Context < ' cx > > ,
1818
1818
it : & ' a clean:: Item ,
1819
1819
s : & ' a clean:: Struct ,
1820
+ should_render_fields : bool ,
1820
1821
}
1821
1822
1822
1823
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
+
1823
1834
fn render_struct < ' b > ( & ' b self ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1824
1835
display_fn ( move |f| {
1825
1836
let cx = self . cx . borrow ( ) ;
@@ -1844,18 +1855,6 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
1844
1855
} )
1845
1856
}
1846
1857
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
-
1859
1858
fn render_field_in_span < ' b > (
1860
1859
& ' b self ,
1861
1860
index : & ' b usize ,
@@ -1913,7 +1912,14 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
1913
1912
}
1914
1913
}
1915
1914
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
+ } )
1917
1923
}
1918
1924
1919
1925
fn item_static ( w : & mut impl fmt:: Write , cx : & mut Context < ' _ > , it : & clean:: Item , s : & clean:: Static ) {
0 commit comments