Skip to content

Commit dcb4056

Browse files
committed
Auto merge of #51078 - GuillaumeGomez:stabilize-formatter, r=SimonSapin
Stabilize Formatter alignment Fixes #27726. cc @SimonSapin
2 parents 63b1070 + fb447f1 commit dcb4056

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/libcore/fmt/mod.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ mod float;
2525
mod num;
2626
mod builders;
2727

28-
#[unstable(feature = "fmt_flags_align", issue = "27726")]
28+
#[stable(feature = "fmt_flags_align", since = "1.28.0")]
2929
/// Possible alignments returned by `Formatter::align`
3030
#[derive(Debug)]
3131
pub enum Alignment {
32+
#[stable(feature = "fmt_flags_align", since = "1.28.0")]
3233
/// Indication that contents should be left-aligned.
3334
Left,
35+
#[stable(feature = "fmt_flags_align", since = "1.28.0")]
3436
/// Indication that contents should be right-aligned.
3537
Right,
38+
#[stable(feature = "fmt_flags_align", since = "1.28.0")]
3639
/// Indication that contents should be center-aligned.
3740
Center,
38-
/// No alignment was requested.
39-
Unknown,
4041
}
4142

4243
#[stable(feature = "debug_builders", since = "1.2.0")]
@@ -1433,8 +1434,6 @@ impl<'a> Formatter<'a> {
14331434
/// # Examples
14341435
///
14351436
/// ```
1436-
/// #![feature(fmt_flags_align)]
1437-
///
14381437
/// extern crate core;
14391438
///
14401439
/// use std::fmt;
@@ -1444,11 +1443,14 @@ impl<'a> Formatter<'a> {
14441443
///
14451444
/// impl fmt::Display for Foo {
14461445
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1447-
/// let s = match formatter.align() {
1448-
/// Alignment::Left => "left",
1449-
/// Alignment::Right => "right",
1450-
/// Alignment::Center => "center",
1451-
/// Alignment::Unknown => "into the void",
1446+
/// let s = if let Some(s) = formatter.align() {
1447+
/// match s {
1448+
/// Alignment::Left => "left",
1449+
/// Alignment::Right => "right",
1450+
/// Alignment::Center => "center",
1451+
/// }
1452+
/// } else {
1453+
/// "into the void"
14521454
/// };
14531455
/// write!(formatter, "{}", s)
14541456
/// }
@@ -1461,14 +1463,13 @@ impl<'a> Formatter<'a> {
14611463
/// assert_eq!(&format!("{}", Foo), "into the void");
14621464
/// }
14631465
/// ```
1464-
#[unstable(feature = "fmt_flags_align", reason = "method was just created",
1465-
issue = "27726")]
1466-
pub fn align(&self) -> Alignment {
1466+
#[stable(feature = "fmt_flags_align", since = "1.28.0")]
1467+
pub fn align(&self) -> Option<Alignment> {
14671468
match self.align {
1468-
rt::v1::Alignment::Left => Alignment::Left,
1469-
rt::v1::Alignment::Right => Alignment::Right,
1470-
rt::v1::Alignment::Center => Alignment::Center,
1471-
rt::v1::Alignment::Unknown => Alignment::Unknown,
1469+
rt::v1::Alignment::Left => Some(Alignment::Left),
1470+
rt::v1::Alignment::Right => Some(Alignment::Right),
1471+
rt::v1::Alignment::Center => Some(Alignment::Center),
1472+
rt::v1::Alignment::Unknown => None,
14721473
}
14731474
}
14741475

0 commit comments

Comments
 (0)