]> git.lizzy.rs Git - rust.git/blob - src/libstd/fmt/rt.rs
Convert most code to new inner attribute syntax.
[rust.git] / src / libstd / 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 fmt::parse;
21 use option::Option;
22
23 pub enum Piece<'a> {
24     String(&'a str),
25     // FIXME(#8259): this shouldn't require the unit-value here
26     CurrentArgument(()),
27     Argument(Argument<'a>),
28 }
29
30 pub struct Argument<'a> {
31     position: Position,
32     format: FormatSpec,
33     method: Option<&'a Method<'a>>
34 }
35
36 pub struct FormatSpec {
37     fill: char,
38     align: parse::Alignment,
39     flags: uint,
40     precision: Count,
41     width: Count,
42 }
43
44 pub enum Count {
45     CountIs(uint), CountIsParam(uint), CountIsNextParam, CountImplied,
46 }
47
48 pub enum Position {
49     ArgumentNext, ArgumentIs(uint)
50 }
51
52 pub enum Method<'a> {
53     Plural(Option<uint>, &'a [PluralArm<'a>], &'a [Piece<'a>]),
54     Select(&'a [SelectArm<'a>], &'a [Piece<'a>]),
55 }
56
57 pub enum PluralSelector {
58     Keyword(parse::PluralKeyword),
59     Literal(uint),
60 }
61
62 pub struct PluralArm<'a> {
63     selector: PluralSelector,
64     result: &'a [Piece<'a>],
65 }
66
67 pub struct SelectArm<'a> {
68     selector: &'a str,
69     result: &'a [Piece<'a>],
70 }