@@ -1595,9 +1595,20 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
1595
1595
cx : std:: cell:: RefCell < & ' a mut Context < ' cx > > ,
1596
1596
it : & ' a clean:: Item ,
1597
1597
s : & ' a clean:: Struct ,
1598
+ should_render_fields : bool ,
1598
1599
}
1599
1600
1600
1601
impl < ' a , ' cx : ' a > ItemStruct < ' a , ' cx > {
1602
+ fn new (
1603
+ cx : std:: cell:: RefCell < & ' a mut Context < ' cx > > ,
1604
+ it : & ' a clean:: Item ,
1605
+ s : & ' a clean:: Struct ,
1606
+ ) -> Self {
1607
+ let should_render_fields = matches ! ( s. ctor_kind, None | Some ( CtorKind :: Fn ) )
1608
+ && struct_field_items ( s) . peekable ( ) . peek ( ) . is_some ( ) ;
1609
+ Self { cx, it, s, should_render_fields }
1610
+ }
1611
+
1601
1612
fn render_struct < ' b > ( & ' b self ) -> impl fmt:: Display + Captures < ' a > + ' b + Captures < ' cx > {
1602
1613
display_fn ( move |f| {
1603
1614
let cx = self . cx . borrow ( ) ;
@@ -1622,18 +1633,6 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
1622
1633
} )
1623
1634
}
1624
1635
1625
- fn fields ( & self ) -> impl Iterator < Item = ( & clean:: Item , & clean:: Type ) > {
1626
- self . s . fields . iter ( ) . filter_map ( |item| match * item. kind {
1627
- clean:: StructFieldItem ( ref ty) => Some ( ( item, ty) ) ,
1628
- _ => None ,
1629
- } )
1630
- }
1631
-
1632
- fn should_render_fields ( & self ) -> bool {
1633
- matches ! ( self . s. ctor_kind, None | Some ( CtorKind :: Fn ) )
1634
- && self . fields ( ) . peekable ( ) . peek ( ) . is_some ( )
1635
- }
1636
-
1637
1636
fn render_field_in_span < ' b > (
1638
1637
& ' b self ,
1639
1638
index : & ' b usize ,
@@ -1691,7 +1690,14 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
1691
1690
}
1692
1691
}
1693
1692
1694
- ItemStruct { cx : std:: cell:: RefCell :: new ( cx) , it, s } . render_into ( w) . unwrap ( ) ;
1693
+ ItemStruct :: new ( std:: cell:: RefCell :: new ( cx) , it, s) . render_into ( w) . unwrap ( ) ;
1694
+ }
1695
+
1696
+ fn struct_field_items ( s : & clean:: Struct ) -> impl Iterator < Item = ( & clean:: Item , & clean:: Type ) > {
1697
+ s. fields . iter ( ) . filter_map ( |item| match * item. kind {
1698
+ clean:: StructFieldItem ( ref ty) => Some ( ( item, ty) ) ,
1699
+ _ => None ,
1700
+ } )
1695
1701
}
1696
1702
1697
1703
fn item_static ( w : & mut impl fmt:: Write , cx : & mut Context < ' _ > , it : & clean:: Item , s : & clean:: Static ) {
0 commit comments