Skip to content

Commit 8aa268e

Browse files
committed
std: Fix rustdoc links with std::fmt::Alignment
This is actually a reexported implementation detail in the `rt::v1` module but rustdoc doesn't like reexporting items from `doc(hidden)` modules. Do what we'd end up doing anyway from an API perspective and make a public-facing `enum` that can be retranslated under the hood if necessary.
1 parent 73db760 commit 8aa268e

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

src/libcore/fmt/mod.rs

+33-12
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,19 @@ use ops::Deref;
2222
use result;
2323
use slice;
2424
use str;
25-
use self::rt::v1::Alignment;
25+
26+
#[unstable(feature = "fmt_flags_align", issue = "27726")]
27+
/// Possible alignments returned by `Formatter::align`
28+
pub enum Alignment {
29+
/// Indication that contents should be left-aligned.
30+
Left,
31+
/// Indication that contents should be right-aligned.
32+
Right,
33+
/// Indication that contents should be center-aligned.
34+
Center,
35+
/// No alignment was requested.
36+
Unknown,
37+
}
2638

2739
#[unstable(feature = "fmt_radix", issue = "27728")]
2840
#[rustc_deprecated(since = "1.7.0", reason = "not used enough to stabilize")]
@@ -780,7 +792,7 @@ pub fn write(output: &mut Write, args: Arguments) -> Result {
780792
width: None,
781793
precision: None,
782794
buf: output,
783-
align: Alignment::Unknown,
795+
align: rt::v1::Alignment::Unknown,
784796
fill: ' ',
785797
args: args.args,
786798
curarg: args.args.iter(),
@@ -920,13 +932,13 @@ impl<'a> Formatter<'a> {
920932
Some(min) if self.sign_aware_zero_pad() => {
921933
self.fill = '0';
922934
try!(write_prefix(self));
923-
self.with_padding(min - width, Alignment::Right, |f| {
935+
self.with_padding(min - width, rt::v1::Alignment::Right, |f| {
924936
f.buf.write_str(buf)
925937
})
926938
}
927939
// Otherwise, the sign and prefix goes after the padding
928940
Some(min) => {
929-
self.with_padding(min - width, Alignment::Right, |f| {
941+
self.with_padding(min - width, rt::v1::Alignment::Right, |f| {
930942
try!(write_prefix(f)); f.buf.write_str(buf)
931943
})
932944
}
@@ -973,7 +985,8 @@ impl<'a> Formatter<'a> {
973985
// If we're under both the maximum and the minimum width, then fill
974986
// up the minimum width with the specified string + some alignment.
975987
Some(width) => {
976-
self.with_padding(width - s.chars().count(), Alignment::Left, |me| {
988+
let align = rt::v1::Alignment::Left;
989+
self.with_padding(width - s.chars().count(), align, |me| {
977990
me.buf.write_str(s)
978991
})
979992
}
@@ -982,20 +995,21 @@ impl<'a> Formatter<'a> {
982995

983996
/// Runs a callback, emitting the correct padding either before or
984997
/// afterwards depending on whether right or left alignment is requested.
985-
fn with_padding<F>(&mut self, padding: usize, default: Alignment,
998+
fn with_padding<F>(&mut self, padding: usize, default: rt::v1::Alignment,
986999
f: F) -> Result
9871000
where F: FnOnce(&mut Formatter) -> Result,
9881001
{
9891002
use char::CharExt;
9901003
let align = match self.align {
991-
Alignment::Unknown => default,
1004+
rt::v1::Alignment::Unknown => default,
9921005
_ => self.align
9931006
};
9941007

9951008
let (pre_pad, post_pad) = match align {
996-
Alignment::Left => (0, padding),
997-
Alignment::Right | Alignment::Unknown => (padding, 0),
998-
Alignment::Center => (padding / 2, (padding + 1) / 2),
1009+
rt::v1::Alignment::Left => (0, padding),
1010+
rt::v1::Alignment::Right |
1011+
rt::v1::Alignment::Unknown => (padding, 0),
1012+
rt::v1::Alignment::Center => (padding / 2, (padding + 1) / 2),
9991013
};
10001014

10011015
let mut fill = [0; 4];
@@ -1033,7 +1047,7 @@ impl<'a> Formatter<'a> {
10331047
// remove the sign from the formatted parts
10341048
formatted.sign = b"";
10351049
width = if width < sign.len() { 0 } else { width - sign.len() };
1036-
align = Alignment::Right;
1050+
align = rt::v1::Alignment::Right;
10371051
self.fill = '0';
10381052
}
10391053

@@ -1116,7 +1130,14 @@ impl<'a> Formatter<'a> {
11161130
/// Flag indicating what form of alignment was requested
11171131
#[unstable(feature = "fmt_flags_align", reason = "method was just created",
11181132
issue = "27726")]
1119-
pub fn align(&self) -> Alignment { self.align }
1133+
pub fn align(&self) -> Alignment {
1134+
match self.align {
1135+
rt::v1::Alignment::Left => Alignment::Left,
1136+
rt::v1::Alignment::Right => Alignment::Right,
1137+
rt::v1::Alignment::Center => Alignment::Center,
1138+
rt::v1::Alignment::Unknown => Alignment::Unknown,
1139+
}
1140+
}
11201141

11211142
/// Optionally specified integer width that the output should be
11221143
#[stable(feature = "fmt_flags", since = "1.5.0")]

0 commit comments

Comments
 (0)