提交 8aa268e7 编写于 作者: A Alex Crichton

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.
上级 73db7601
......@@ -22,7 +22,19 @@
use result;
use slice;
use str;
use self::rt::v1::Alignment;
#[unstable(feature = "fmt_flags_align", issue = "27726")]
/// Possible alignments returned by `Formatter::align`
pub enum Alignment {
/// Indication that contents should be left-aligned.
Left,
/// Indication that contents should be right-aligned.
Right,
/// Indication that contents should be center-aligned.
Center,
/// No alignment was requested.
Unknown,
}
#[unstable(feature = "fmt_radix", issue = "27728")]
#[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 {
width: None,
precision: None,
buf: output,
align: Alignment::Unknown,
align: rt::v1::Alignment::Unknown,
fill: ' ',
args: args.args,
curarg: args.args.iter(),
......@@ -920,13 +932,13 @@ pub fn pad_integral(&mut self,
Some(min) if self.sign_aware_zero_pad() => {
self.fill = '0';
try!(write_prefix(self));
self.with_padding(min - width, Alignment::Right, |f| {
self.with_padding(min - width, rt::v1::Alignment::Right, |f| {
f.buf.write_str(buf)
})
}
// Otherwise, the sign and prefix goes after the padding
Some(min) => {
self.with_padding(min - width, Alignment::Right, |f| {
self.with_padding(min - width, rt::v1::Alignment::Right, |f| {
try!(write_prefix(f)); f.buf.write_str(buf)
})
}
......@@ -973,7 +985,8 @@ pub fn pad(&mut self, s: &str) -> Result {
// If we're under both the maximum and the minimum width, then fill
// up the minimum width with the specified string + some alignment.
Some(width) => {
self.with_padding(width - s.chars().count(), Alignment::Left, |me| {
let align = rt::v1::Alignment::Left;
self.with_padding(width - s.chars().count(), align, |me| {
me.buf.write_str(s)
})
}
......@@ -982,20 +995,21 @@ pub fn pad(&mut self, s: &str) -> Result {
/// Runs a callback, emitting the correct padding either before or
/// afterwards depending on whether right or left alignment is requested.
fn with_padding<F>(&mut self, padding: usize, default: Alignment,
fn with_padding<F>(&mut self, padding: usize, default: rt::v1::Alignment,
f: F) -> Result
where F: FnOnce(&mut Formatter) -> Result,
{
use char::CharExt;
let align = match self.align {
Alignment::Unknown => default,
rt::v1::Alignment::Unknown => default,
_ => self.align
};
let (pre_pad, post_pad) = match align {
Alignment::Left => (0, padding),
Alignment::Right | Alignment::Unknown => (padding, 0),
Alignment::Center => (padding / 2, (padding + 1) / 2),
rt::v1::Alignment::Left => (0, padding),
rt::v1::Alignment::Right |
rt::v1::Alignment::Unknown => (padding, 0),
rt::v1::Alignment::Center => (padding / 2, (padding + 1) / 2),
};
let mut fill = [0; 4];
......@@ -1033,7 +1047,7 @@ fn pad_formatted_parts(&mut self, formatted: &flt2dec::Formatted) -> Result {
// remove the sign from the formatted parts
formatted.sign = b"";
width = if width < sign.len() { 0 } else { width - sign.len() };
align = Alignment::Right;
align = rt::v1::Alignment::Right;
self.fill = '0';
}
......@@ -1116,7 +1130,14 @@ pub fn fill(&self) -> char { self.fill }
/// Flag indicating what form of alignment was requested
#[unstable(feature = "fmt_flags_align", reason = "method was just created",
issue = "27726")]
pub fn align(&self) -> Alignment { self.align }
pub fn align(&self) -> Alignment {
match self.align {
rt::v1::Alignment::Left => Alignment::Left,
rt::v1::Alignment::Right => Alignment::Right,
rt::v1::Alignment::Center => Alignment::Center,
rt::v1::Alignment::Unknown => Alignment::Unknown,
}
}
/// Optionally specified integer width that the output should be
#[stable(feature = "fmt_flags", since = "1.5.0")]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册