@@ -22,7 +22,19 @@ use ops::Deref;
22
22
use result;
23
23
use slice;
24
24
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
+ }
26
38
27
39
#[ unstable( feature = "fmt_radix" , issue = "27728" ) ]
28
40
#[ 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 {
780
792
width : None ,
781
793
precision : None ,
782
794
buf : output,
783
- align : Alignment :: Unknown ,
795
+ align : rt :: v1 :: Alignment :: Unknown ,
784
796
fill : ' ' ,
785
797
args : args. args ,
786
798
curarg : args. args . iter ( ) ,
@@ -920,13 +932,13 @@ impl<'a> Formatter<'a> {
920
932
Some ( min) if self . sign_aware_zero_pad ( ) => {
921
933
self . fill = '0' ;
922
934
try!( write_prefix ( self ) ) ;
923
- self . with_padding ( min - width, Alignment :: Right , |f| {
935
+ self . with_padding ( min - width, rt :: v1 :: Alignment :: Right , |f| {
924
936
f. buf . write_str ( buf)
925
937
} )
926
938
}
927
939
// Otherwise, the sign and prefix goes after the padding
928
940
Some ( min) => {
929
- self . with_padding ( min - width, Alignment :: Right , |f| {
941
+ self . with_padding ( min - width, rt :: v1 :: Alignment :: Right , |f| {
930
942
try!( write_prefix ( f) ) ; f. buf . write_str ( buf)
931
943
} )
932
944
}
@@ -973,7 +985,8 @@ impl<'a> Formatter<'a> {
973
985
// If we're under both the maximum and the minimum width, then fill
974
986
// up the minimum width with the specified string + some alignment.
975
987
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| {
977
990
me. buf . write_str ( s)
978
991
} )
979
992
}
@@ -982,20 +995,21 @@ impl<'a> Formatter<'a> {
982
995
983
996
/// Runs a callback, emitting the correct padding either before or
984
997
/// 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 ,
986
999
f : F ) -> Result
987
1000
where F : FnOnce ( & mut Formatter ) -> Result ,
988
1001
{
989
1002
use char:: CharExt ;
990
1003
let align = match self . align {
991
- Alignment :: Unknown => default,
1004
+ rt :: v1 :: Alignment :: Unknown => default,
992
1005
_ => self . align
993
1006
} ;
994
1007
995
1008
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 ) ,
999
1013
} ;
1000
1014
1001
1015
let mut fill = [ 0 ; 4 ] ;
@@ -1033,7 +1047,7 @@ impl<'a> Formatter<'a> {
1033
1047
// remove the sign from the formatted parts
1034
1048
formatted. sign = b"" ;
1035
1049
width = if width < sign. len ( ) { 0 } else { width - sign. len ( ) } ;
1036
- align = Alignment :: Right ;
1050
+ align = rt :: v1 :: Alignment :: Right ;
1037
1051
self . fill = '0' ;
1038
1052
}
1039
1053
@@ -1116,7 +1130,14 @@ impl<'a> Formatter<'a> {
1116
1130
/// Flag indicating what form of alignment was requested
1117
1131
#[ unstable( feature = "fmt_flags_align" , reason = "method was just created" ,
1118
1132
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
+ }
1120
1141
1121
1142
/// Optionally specified integer width that the output should be
1122
1143
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
0 commit comments