Skip to content

Commit

Permalink
fmt::FormattingOptions: Renamed alignment to align
Browse files Browse the repository at this point in the history
Likewise for `get_alignment`. This is how the method is named on `Formatter`, I
want to keep it consistent.
  • Loading branch information
EliasHolzmann committed Nov 27, 2023
1 parent a6abef0 commit cc52c71
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ pub struct FormattingOptions {
sign_aware_zero_pad: bool,
alternate: bool,
fill: char,
alignment: Option<Alignment>,
align: Option<Alignment>,
width: Option<usize>,
precision: Option<usize>,
debug_as_hex: Option<DebugAsHex>,
Expand All @@ -300,7 +300,7 @@ impl FormattingOptions {
sign_aware_zero_pad: false,
alternate: false,
fill: ' ',
alignment: None,
align: None,
width: None,
precision: None,
debug_as_hex: None,
Expand Down Expand Up @@ -357,15 +357,15 @@ impl FormattingOptions {
/// The alignment specifies how the value being formatted should be
/// positioned if it is smaller than the width of the formatter.
#[unstable(feature = "formatting_options", issue = "118117")]
pub fn alignment(&mut self, alignment: Option<Alignment>) -> &mut Self {
self.alignment = alignment;
pub fn align(&mut self, align: Option<Alignment>) -> &mut Self {
self.align = align;
self
}
/// Sets or removes the width.
///
/// This is a parameter for the “minimum width” that the format should take
/// up. If the value’s string does not fill up this many characters, then
/// the padding specified by [`FormattingOptions::fill`]/[`FormattingOptions::alignment`]
/// the padding specified by [`FormattingOptions::fill`]/[`FormattingOptions::align`]
/// will be used to take up the required space.
#[unstable(feature = "formatting_options", issue = "118117")]
pub fn width(&mut self, width: Option<usize>) -> &mut Self {
Expand Down Expand Up @@ -416,8 +416,8 @@ impl FormattingOptions {
}
/// Returns the current alignment.
#[unstable(feature = "formatting_options", issue = "118117")]
pub fn get_alignment(&self) -> Option<Alignment> {
self.alignment
pub fn get_align(&self) -> Option<Alignment> {
self.align
}
/// Returns the current width.
#[unstable(feature = "formatting_options", issue = "118117")]
Expand Down Expand Up @@ -1393,7 +1393,7 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {

unsafe fn run(fmt: &mut Formatter<'_>, arg: &rt::Placeholder, args: &[rt::Argument<'_>]) -> Result {
fmt.options.fill(arg.fill);
fmt.options.alignment(arg.align.into());
fmt.options.align(arg.align.into());
fmt.options.flags(arg.flags);
// SAFETY: arg and args come from the same Arguments,
// which guarantees the indexes are always within bounds.
Expand Down Expand Up @@ -1556,13 +1556,13 @@ impl<'a> Formatter<'a> {
Some(min) if self.sign_aware_zero_pad() => {
let old_fill = crate::mem::replace(&mut self.options.fill, '0');
let old_align =
crate::mem::replace(&mut self.options.alignment, Some(Alignment::Right));
crate::mem::replace(&mut self.options.align, Some(Alignment::Right));
write_prefix(self, sign, prefix)?;
let post_padding = self.padding(min - width, Alignment::Right)?;
self.buf.write_str(buf)?;
post_padding.write(self)?;
self.options.fill = old_fill;
self.options.alignment = old_align;
self.options.align = old_align;
Ok(())
}
// Otherwise, the sign and prefix goes after the padding
Expand Down Expand Up @@ -1697,7 +1697,7 @@ impl<'a> Formatter<'a> {
formatted.sign = "";
width = width.saturating_sub(sign.len());
self.options.fill('0');
self.options.alignment(Some(Alignment::Right));
self.options.align(Some(Alignment::Right));
}

// remaining parts go through the ordinary padding process.
Expand All @@ -1715,7 +1715,7 @@ impl<'a> Formatter<'a> {
post_padding.write(self)
};
self.options.fill(old_fill);
self.options.alignment(old_align);
self.options.align(old_align);
ret
} else {
// this is the common case and we take a shortcut
Expand Down Expand Up @@ -1899,7 +1899,7 @@ impl<'a> Formatter<'a> {
#[must_use]
#[stable(feature = "fmt_flags_align", since = "1.28.0")]
pub fn align(&self) -> Option<Alignment> {
self.options.get_alignment()
self.options.get_align()
}

/// Optionally specified integer width that the output should be.
Expand Down

0 comments on commit cc52c71

Please sign in to comment.