]> git.proxmox.com Git - rustc.git/blob - library/core/src/fmt/rt/v1.rs
New upstream version 1.70.0+dfsg1
[rustc.git] / library / core / src / fmt / rt / v1.rs
1 //! This is an internal module used by the ifmt! runtime. These structures are
2 //! emitted to static arrays to precompile format strings ahead of time.
3 //!
4 //! These definitions are similar to their `ct` equivalents, but differ in that
5 //! these can be statically allocated and are slightly optimized for the runtime
6 #![allow(missing_debug_implementations)]
7
8 #[lang = "format_placeholder"]
9 #[derive(Copy, Clone)]
10 // FIXME: Rename this to Placeholder
11 pub struct Argument {
12 pub position: usize,
13 pub format: FormatSpec,
14 }
15
16 #[derive(Copy, Clone)]
17 pub struct FormatSpec {
18 pub fill: char,
19 pub align: Alignment,
20 pub flags: u32,
21 pub precision: Count,
22 pub width: Count,
23 }
24
25 impl Argument {
26 #[inline(always)]
27 pub const fn new(
28 position: usize,
29 fill: char,
30 align: Alignment,
31 flags: u32,
32 precision: Count,
33 width: Count,
34 ) -> Self {
35 Self { position, format: FormatSpec { fill, align, flags, precision, width } }
36 }
37 }
38
39 /// Possible alignments that can be requested as part of a formatting directive.
40 #[lang = "format_alignment"]
41 #[derive(Copy, Clone, PartialEq, Eq)]
42 pub enum Alignment {
43 /// Indication that contents should be left-aligned.
44 Left,
45 /// Indication that contents should be right-aligned.
46 Right,
47 /// Indication that contents should be center-aligned.
48 Center,
49 /// No alignment was requested.
50 Unknown,
51 }
52
53 /// Used by [width](https://doc.rust-lang.org/std/fmt/#width) and [precision](https://doc.rust-lang.org/std/fmt/#precision) specifiers.
54 #[lang = "format_count"]
55 #[derive(Copy, Clone)]
56 pub enum Count {
57 /// Specified with a literal number, stores the value
58 Is(usize),
59 /// Specified using `$` and `*` syntaxes, stores the index into `args`
60 Param(usize),
61 /// Not specified
62 Implied,
63 }