]> git.lizzy.rs Git - rust.git/blob - src/libcore/fmt/rt.rs
std: Rename {Eq,Ord} to Partial{Eq,Ord}
[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 #![allow(missing_doc)]
18 #![doc(hidden)]
19
20 use option::Option;
21
22 pub enum Piece<'a> {
23     String(&'a str),
24     // FIXME(#8259): this shouldn't require the unit-value here
25     CurrentArgument(()),
26     Argument(Argument<'a>),
27 }
28
29 pub struct Argument<'a> {
30     pub position: Position,
31     pub format: FormatSpec,
32     pub method: Option<&'a Method<'a>>
33 }
34
35 pub struct FormatSpec {
36     pub fill: char,
37     pub align: Alignment,
38     pub flags: uint,
39     pub precision: Count,
40     pub width: Count,
41 }
42
43 #[deriving(PartialEq)]
44 pub enum Alignment {
45     AlignLeft,
46     AlignRight,
47     AlignUnknown,
48 }
49
50 pub enum Count {
51     CountIs(uint), CountIsParam(uint), CountIsNextParam, CountImplied,
52 }
53
54 pub enum Position {
55     ArgumentNext, ArgumentIs(uint)
56 }
57
58 pub enum Flag {
59     FlagSignPlus,
60     FlagSignMinus,
61     FlagAlternate,
62     FlagSignAwareZeroPad,
63 }
64
65 pub enum Method<'a> {
66     Plural(Option<uint>, &'a [PluralArm<'a>], &'a [Piece<'a>]),
67     Select(&'a [SelectArm<'a>], &'a [Piece<'a>]),
68 }
69
70 pub enum PluralSelector {
71     Keyword(PluralKeyword),
72     Literal(uint),
73 }
74
75 pub enum PluralKeyword {
76     Zero,
77     One,
78     Two,
79     Few,
80     Many,
81 }
82
83 pub struct PluralArm<'a> {
84     pub selector: PluralSelector,
85     pub result: &'a [Piece<'a>],
86 }
87
88 pub struct SelectArm<'a> {
89     pub selector: &'a str,
90     pub result: &'a [Piece<'a>],
91 }