Skip to content

Commit d107e58

Browse files
committed
Documented fmt! expression syntax.
Closes #3280
1 parent d106ef8 commit d107e58

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

src/libcore/extfmt.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
1-
#[doc(hidden)];
1+
//! Support for fmt! expressions.
2+
//!
3+
//! The syntax is close to that of Posix format strings:
4+
//!
5+
//! ~~~~~~
6+
//! Format := '%' Parameter? Flag* Width? Precision? Type
7+
//! Parameter := [0-9]+ '$'
8+
//! Flag := [ 0#+-]
9+
//! Width := Parameter | [0-9]+
10+
//! Precision := '.' [0-9]+
11+
//! Type := [bcdfiostuxX?]
12+
//! ~~~~~~
13+
//!
14+
//! * Parameter is the 1-based argument to apply the format to. Currently not implemented.
15+
//! * Flag 0 causes leading zeros to be used for padding when converting numbers.
16+
//! * Flag # causes the conversion to be done in an *alternative* manner. Currently not implemented.
17+
//! * Flag + causes signed numbers to always be prepended with a sign character.
18+
//! * Flag - left justifies the result
19+
//! * Width specifies the minimum field width of the result. By default leading spaces are added.
20+
//! * Precision specifies the minimum number of digits for integral types and the minimum number
21+
//! of decimal places for float.
22+
//!
23+
//! The types currently supported are:
24+
//!
25+
//! * b - bool
26+
//! * c - char
27+
//! * d - int
28+
//! * f - float
29+
//! * i - int (same as d)
30+
//! * o - uint as octal
31+
//! * t - uint as binary
32+
//! * u - uint
33+
//! * x - uint as lower-case hexadecimal
34+
//! * X - uint as upper-case hexadecimal
35+
//! * s - str (any flavor)
36+
//! * ? - arbitrary type (does not use the to_str trait)
37+
238
// NB: transitionary, de-mode-ing.
339
#[forbid(deprecated_mode)];
440
#[forbid(deprecated_pattern)];
@@ -44,6 +80,7 @@ use option::{Some, None};
4480
*/
4581

4682
// Functions used by the fmt extension at compile time
83+
#[doc(hidden)]
4784
pub mod ct {
4885
pub enum Signedness { Signed, Unsigned, }
4986
pub enum Caseness { CaseUpper, CaseLower, }
@@ -277,6 +314,7 @@ pub mod ct {
277314
// decisions made a runtime. If it proves worthwhile then some of these
278315
// conditions can be evaluated at compile-time. For now though it's cleaner to
279316
// implement it 0this way, I think.
317+
#[doc(hidden)]
280318
pub mod rt {
281319
pub const flag_none : u32 = 0u32;
282320
pub const flag_left_justify : u32 = 0b00000000000001u32;
@@ -464,6 +502,7 @@ pub mod rt {
464502
}
465503
}
466504

505+
// Bulk of the tests are in src/test/run-pass/syntax-extension-fmt.rs
467506
#[cfg(test)]
468507
mod test {
469508
#[test]

0 commit comments

Comments
 (0)