]> git.lizzy.rs Git - rust.git/blob - src/libcore/fmt/rt.rs
Register new snapshots
[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 #[doc(hidden)]
18 pub struct Argument<'a> {
19     pub position: Position,
20     pub format: FormatSpec,
21 }
22
23 #[doc(hidden)]
24 pub struct FormatSpec {
25     pub fill: char,
26     pub align: Alignment,
27     pub flags: uint,
28     pub precision: Count,
29     pub width: Count,
30 }
31
32 /// Possible alignments that can be requested as part of a formatting directive.
33 #[deriving(PartialEq)]
34 pub enum Alignment {
35     /// Indication that contents should be left-aligned.
36     AlignLeft,
37     /// Indication that contents should be right-aligned.
38     AlignRight,
39     /// Indication that contents should be center-aligned.
40     AlignCenter,
41     /// No alignment was requested.
42     AlignUnknown,
43 }
44
45 #[doc(hidden)]
46 pub enum Count {
47     CountIs(uint), CountIsParam(uint), CountIsNextParam, CountImplied,
48 }
49
50 #[doc(hidden)]
51 pub enum Position {
52     ArgumentNext, ArgumentIs(uint)
53 }
54
55 /// Flags which can be passed to formatting via a directive.
56 ///
57 /// These flags are discovered through the `flags` field of the `Formatter`
58 /// structure. The flag in that structure is a union of these flags into a
59 /// `uint` where each flag's discriminant is the corresponding bit.
60 pub enum Flag {
61     /// A flag which enables number formatting to always print the sign of a
62     /// number.
63     FlagSignPlus,
64     /// Currently not a used flag
65     FlagSignMinus,
66     /// Indicates that the "alternate formatting" for a type should be used.
67     ///
68     /// The meaning of this flag is type-specific.
69     FlagAlternate,
70     /// Indicates that padding should be done with a `0` character as well as
71     /// being aware of the sign to be printed.
72     FlagSignAwareZeroPad,
73 }