@@ -1466,14 +1466,14 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
1466
1466
}
1467
1467
1468
1468
unsafe fn run ( fmt : & mut Formatter < ' _ > , arg : & rt:: Placeholder , args : & [ rt:: Argument < ' _ > ] ) -> Result {
1469
- fmt. options . fill ( arg. fill ) ;
1470
- fmt. options . align ( arg. align . into ( ) ) ;
1471
- fmt. options . flags ( arg. flags ) ;
1469
+ fmt. options . fill = arg. fill ;
1470
+ fmt. options . align = arg. align . into ( ) ;
1471
+ fmt. options . flags = arg. flags ;
1472
1472
// SAFETY: arg and args come from the same Arguments,
1473
1473
// which guarantees the indexes are always within bounds.
1474
1474
unsafe {
1475
- fmt. options . width ( getcount ( args, & arg. width ) ) ;
1476
- fmt. options . precision ( getcount ( args, & arg. precision ) ) ;
1475
+ fmt. options . width = getcount ( args, & arg. width ) ;
1476
+ fmt. options . precision = getcount ( args, & arg. precision ) ;
1477
1477
}
1478
1478
1479
1479
// Extract the correct argument
@@ -1613,7 +1613,7 @@ impl<'a> Formatter<'a> {
1613
1613
}
1614
1614
1615
1615
// The `width` field is more of a `min-width` parameter at this point.
1616
- match self . width ( ) {
1616
+ match self . options . width {
1617
1617
// If there's no minimum length requirements then we can just
1618
1618
// write the bytes.
1619
1619
None => {
@@ -1682,12 +1682,12 @@ impl<'a> Formatter<'a> {
1682
1682
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1683
1683
pub fn pad ( & mut self , s : & str ) -> Result {
1684
1684
// Make sure there's a fast path up front
1685
- if self . width ( ) . is_none ( ) && self . precision ( ) . is_none ( ) {
1685
+ if self . options . width . is_none ( ) && self . options . precision . is_none ( ) {
1686
1686
return self . buf . write_str ( s) ;
1687
1687
}
1688
1688
// The `precision` field can be interpreted as a `max-width` for the
1689
1689
// string being formatted.
1690
- let s = if let Some ( max) = self . precision ( ) {
1690
+ let s = if let Some ( max) = self . options . precision {
1691
1691
// If our string is longer that the precision, then we must have
1692
1692
// truncation. However other flags like `fill`, `width` and `align`
1693
1693
// must act as always.
@@ -1704,7 +1704,7 @@ impl<'a> Formatter<'a> {
1704
1704
& s
1705
1705
} ;
1706
1706
// The `width` field is more of a `min-width` parameter at this point.
1707
- match self . width ( ) {
1707
+ match self . options . width {
1708
1708
// If we're under the maximum length, and there's no minimum length
1709
1709
// requirements, then we can just emit the string
1710
1710
None => self . buf . write_str ( s) ,
@@ -1745,10 +1745,10 @@ impl<'a> Formatter<'a> {
1745
1745
} ;
1746
1746
1747
1747
for _ in 0 ..pre_pad {
1748
- self . buf . write_char ( self . fill ( ) ) ?;
1748
+ self . buf . write_char ( self . options . fill ) ?;
1749
1749
}
1750
1750
1751
- Ok ( PostPadding :: new ( self . fill ( ) , post_pad) )
1751
+ Ok ( PostPadding :: new ( self . options . fill , post_pad) )
1752
1752
}
1753
1753
1754
1754
/// Takes the formatted parts and applies the padding.
@@ -1760,12 +1760,12 @@ impl<'a> Formatter<'a> {
1760
1760
///
1761
1761
/// Any `numfmt::Part::Copy` parts in `formatted` must contain valid UTF-8.
1762
1762
unsafe fn pad_formatted_parts ( & mut self , formatted : & numfmt:: Formatted < ' _ > ) -> Result {
1763
- if let Some ( mut width) = self . width ( ) {
1763
+ if let Some ( mut width) = self . options . width {
1764
1764
// for the sign-aware zero padding, we render the sign first and
1765
1765
// behave as if we had no sign from the beginning.
1766
1766
let mut formatted = formatted. clone ( ) ;
1767
- let old_fill = self . fill ( ) ;
1768
- let old_align = self . align ( ) ;
1767
+ let old_fill = self . options . fill ;
1768
+ let old_align = self . options . align ;
1769
1769
if self . sign_aware_zero_pad ( ) {
1770
1770
// a sign always goes first
1771
1771
let sign = formatted. sign ;
@@ -1774,8 +1774,8 @@ impl<'a> Formatter<'a> {
1774
1774
// remove the sign from the formatted parts
1775
1775
formatted. sign = "" ;
1776
1776
width = width. saturating_sub ( sign. len ( ) ) ;
1777
- self . options . fill ( '0' ) ;
1778
- self . options . align ( Some ( Alignment :: Right ) ) ;
1777
+ self . options . fill = '0' ;
1778
+ self . options . align = Some ( Alignment :: Right ) ;
1779
1779
}
1780
1780
1781
1781
// remaining parts go through the ordinary padding process.
@@ -1792,8 +1792,8 @@ impl<'a> Formatter<'a> {
1792
1792
}
1793
1793
post_padding. write ( self )
1794
1794
} ;
1795
- self . options . fill ( old_fill) ;
1796
- self . options . align ( old_align) ;
1795
+ self . options . fill = old_fill;
1796
+ self . options . align = old_align;
1797
1797
ret
1798
1798
} else {
1799
1799
// this is the common case and we take a shortcut
@@ -1919,7 +1919,7 @@ impl<'a> Formatter<'a> {
1919
1919
or `sign_aware_zero_pad` methods instead"
1920
1920
) ]
1921
1921
pub fn flags ( & self ) -> u32 {
1922
- self . options . get_flags ( )
1922
+ self . options . flags
1923
1923
}
1924
1924
1925
1925
/// Returns the character used as 'fill' whenever there is alignment.
@@ -1952,7 +1952,7 @@ impl<'a> Formatter<'a> {
1952
1952
#[ must_use]
1953
1953
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
1954
1954
pub fn fill ( & self ) -> char {
1955
- self . options . get_fill ( )
1955
+ self . options . fill
1956
1956
}
1957
1957
1958
1958
/// Returns a flag indicating what form of alignment was requested.
@@ -1987,7 +1987,7 @@ impl<'a> Formatter<'a> {
1987
1987
#[ must_use]
1988
1988
#[ stable( feature = "fmt_flags_align" , since = "1.28.0" ) ]
1989
1989
pub fn align ( & self ) -> Option < Alignment > {
1990
- self . options . get_align ( )
1990
+ self . options . align
1991
1991
}
1992
1992
1993
1993
/// Returns the optionally specified integer width that the output should be.
@@ -2017,7 +2017,7 @@ impl<'a> Formatter<'a> {
2017
2017
#[ must_use]
2018
2018
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
2019
2019
pub fn width ( & self ) -> Option < usize > {
2020
- self . options . get_width ( )
2020
+ self . options . width
2021
2021
}
2022
2022
2023
2023
/// Returns the optionally specified precision for numeric types.
@@ -2048,7 +2048,7 @@ impl<'a> Formatter<'a> {
2048
2048
#[ must_use]
2049
2049
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
2050
2050
pub fn precision ( & self ) -> Option < usize > {
2051
- self . options . get_precision ( )
2051
+ self . options . precision
2052
2052
}
2053
2053
2054
2054
/// Determines if the `+` flag was specified.
@@ -2080,7 +2080,7 @@ impl<'a> Formatter<'a> {
2080
2080
#[ must_use]
2081
2081
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
2082
2082
pub fn sign_plus ( & self ) -> bool {
2083
- self . options . get_sign ( ) == Some ( Sign :: Plus )
2083
+ self . options . flags & ( 1 << rt :: Flag :: SignPlus as u32 ) != 0
2084
2084
}
2085
2085
2086
2086
/// Determines if the `-` flag was specified.
@@ -2109,7 +2109,7 @@ impl<'a> Formatter<'a> {
2109
2109
#[ must_use]
2110
2110
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
2111
2111
pub fn sign_minus ( & self ) -> bool {
2112
- self . options . get_sign ( ) == Some ( Sign :: Minus )
2112
+ self . options . flags & ( 1 << rt :: Flag :: SignMinus as u32 ) != 0
2113
2113
}
2114
2114
2115
2115
/// Determines if the `#` flag was specified.
@@ -2137,7 +2137,7 @@ impl<'a> Formatter<'a> {
2137
2137
#[ must_use]
2138
2138
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
2139
2139
pub fn alternate ( & self ) -> bool {
2140
- self . options . get_alternate ( )
2140
+ self . options . flags & ( 1 << rt :: Flag :: Alternate as u32 ) != 0
2141
2141
}
2142
2142
2143
2143
/// Determines if the `0` flag was specified.
@@ -2163,7 +2163,7 @@ impl<'a> Formatter<'a> {
2163
2163
#[ must_use]
2164
2164
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
2165
2165
pub fn sign_aware_zero_pad ( & self ) -> bool {
2166
- self . options . get_sign_aware_zero_pad ( )
2166
+ self . options . flags & ( 1 << rt :: Flag :: SignAwareZeroPad as u32 ) != 0
2167
2167
}
2168
2168
2169
2169
// FIXME: Decide what public API we want for these two flags.
@@ -2753,7 +2753,7 @@ impl Debug for char {
2753
2753
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2754
2754
impl Display for char {
2755
2755
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
2756
- if f. width ( ) . is_none ( ) && f. precision ( ) . is_none ( ) {
2756
+ if f. options . width . is_none ( ) && f. options . precision . is_none ( ) {
2757
2757
f. write_char ( * self )
2758
2758
} else {
2759
2759
f. pad ( self . encode_utf8 ( & mut [ 0 ; 4 ] ) )
@@ -2777,28 +2777,26 @@ impl<T: ?Sized> Pointer for *const T {
2777
2777
///
2778
2778
/// [problematic]: https://github.com/rust-lang/rust/issues/95489
2779
2779
pub ( crate ) fn pointer_fmt_inner ( ptr_addr : usize , f : & mut Formatter < ' _ > ) -> Result {
2780
- let old_width = f. width ( ) ;
2781
- let old_alternate = f. alternate ( ) ;
2782
- let old_zero_pad = f. sign_aware_zero_pad ( ) ;
2780
+ let old_width = f. options . width ;
2781
+ let old_flags = f. options . flags ;
2783
2782
2784
2783
// The alternate flag is already treated by LowerHex as being special-
2785
2784
// it denotes whether to prefix with 0x. We use it to work out whether
2786
2785
// or not to zero extend, and then unconditionally set it to get the
2787
2786
// prefix.
2788
2787
if f. alternate ( ) {
2789
- f. options . sign_aware_zero_pad ( true ) ;
2788
+ f. options . flags |= 1 << ( rt :: Flag :: SignAwareZeroPad as u32 ) ;
2790
2789
2791
- if f. width ( ) . is_none ( ) {
2792
- f. options . width ( Some ( ( usize:: BITS / 4 ) as usize + 2 ) ) ;
2790
+ if f. options . width . is_none ( ) {
2791
+ f. options . width = Some ( ( usize:: BITS / 4 ) as usize + 2 ) ;
2793
2792
}
2794
2793
}
2795
- f. options . alternate ( true ) ;
2794
+ f. options . flags |= 1 << ( rt :: Flag :: Alternate as u32 ) ;
2796
2795
2797
2796
let ret = LowerHex :: fmt ( & ptr_addr, f) ;
2798
2797
2799
- f. options . width ( old_width) ;
2800
- f. options . alternate ( old_alternate) ;
2801
- f. options . sign_aware_zero_pad ( old_zero_pad) ;
2798
+ f. options . width = old_width;
2799
+ f. options . flags = old_flags;
2802
2800
2803
2801
ret
2804
2802
}
0 commit comments