]> git.lizzy.rs Git - rust.git/blob - src/libcore/fmt/rt.rs
auto merge of #19628 : jbranchaud/rust/add-string-as-string-doctest, r=steveklabnik
[rust.git] / src / libcore / fmt / rt.rs
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! This is an internal module used by the ifmt! runtime. These structures are
12 //! emitted to static arrays to precompile format strings ahead of time.
13 //!
14 //! These definitions are similar to their `ct` equivalents, but differ in that
15 //! these can be statically allocated and are slightly optimized for the runtime
16
17 #![experimental = "implementation detail of the `format_args!` macro"]
18
19 pub use self::Alignment::*;
20 pub use self::Count::*;
21 pub use self::Position::*;
22 pub use self::Flag::*;
23 use kinds::Copy;
24
25 #[doc(hidden)]
26 pub struct Argument<'a> {
27     pub position: Position,
28     pub format: FormatSpec,
29 }
30
31 impl<'a> Copy for Argument<'a> {}
32
33 #[doc(hidden)]
34 pub struct FormatSpec {
35     pub fill: char,
36     pub align: Alignment,
37     pub flags: uint,
38     pub precision: Count,
39     pub width: Count,
40 }
41
42 impl Copy for FormatSpec {}
43
44 /// Possible alignments that can be requested as part of a formatting directive.
45 #[deriving(PartialEq)]
46 pub enum Alignment {
47     /// Indication that contents should be left-aligned.
48     AlignLeft,
49     /// Indication that contents should be right-aligned.
50     AlignRight,
51     /// Indication that contents should be center-aligned.
52     AlignCenter,
53     /// No alignment was requested.
54     AlignUnknown,
55 }
56
57 impl Copy for Alignment {}
58
59 #[doc(hidden)]
60 pub enum Count {
61     CountIs(uint), CountIsParam(uint), CountIsNextParam, CountImplied,
62 }
63
64 impl Copy for Count {}
65
66 #[doc(hidden)]
67 pub enum Position {
68     ArgumentNext, ArgumentIs(uint)
69 }
70
71 impl Copy for Position {}
72
73 /// Flags which can be passed to formatting via a directive.
74 ///
75 /// These flags are discovered through the `flags` field of the `Formatter`
76 /// structure. The flag in that structure is a union of these flags into a
77 /// `uint` where each flag's discriminant is the corresponding bit.
78 pub enum Flag {
79     /// A flag which enables number formatting to always print the sign of a
80     /// number.
81     FlagSignPlus,
82     /// Currently not a used flag
83     FlagSignMinus,
84     /// Indicates that the "alternate formatting" for a type should be used.
85     ///
86     /// The meaning of this flag is type-specific.
87     FlagAlternate,
88     /// Indicates that padding should be done with a `0` character as well as
89     /// being aware of the sign to be printed.
90     FlagSignAwareZeroPad,
91 }
92
93 impl Copy for Flag {}