2020-04-17 07:37:18 +00:00
< style >
body { margin: 0; }
pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
.lifetime { color: #DFAF8F; font-style: italic; }
.comment { color: #7F9F7F; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
.string_literal { color: #CC9393; }
.field { color: #94BFF3; }
.function { color: #93E0E3; }
2020-06-08 13:23:03 +00:00
.function.unsafe { color: #BC8383; }
.operator.unsafe { color: #BC8383; }
2020-04-17 07:37:18 +00:00
.parameter { color: #94BFF3; }
.text { color: #DCDCCC; }
.type { color: #7CB8BB; }
.builtin_type { color: #8CD0D3; }
.type_param { color: #DFAF8F; }
.attribute { color: #94BFF3; }
.numeric_literal { color: #BFEBBF; }
2020-05-21 16:40:52 +00:00
.bool_literal { color: #BFE6EB; }
2020-04-17 07:37:18 +00:00
.macro { color: #94BFF3; }
.module { color: #AFD8AF; }
.variable { color: #DCDCCC; }
2020-04-28 07:44:20 +00:00
.format_specifier { color: #CC696B; }
2020-04-17 07:37:18 +00:00
.mutable { text-decoration: underline; }
2020-06-14 12:43:43 +00:00
.unresolved_reference { color: #FC5555; }
2020-06-17 13:27:13 +00:00
.escape_sequence { color: #94BFF3; }
2020-04-17 07:37:18 +00:00
.keyword { color: #F0DFAF; font-weight: bold; }
.keyword.unsafe { color: #BC8383; font-weight: bold; }
.control { font-style: italic; }
< / style >
2020-05-10 15:08:54 +00:00
< pre > < code > < span class = "macro" > macro_rules!< / span > < span class = "macro declaration" > println< / span > {
2020-04-17 07:37:18 +00:00
($($arg:tt)*) => ({
$< span class = "keyword" > crate< / span > ::io::_print($< span class = "keyword" > crate< / span > ::format_args_nl!($($arg)*));
})
}
#[rustc_builtin_macro]
2020-05-10 15:08:54 +00:00
< span class = "macro" > macro_rules!< / span > < span class = "macro declaration" > format_args_nl< / span > {
2020-04-17 07:37:18 +00:00
($fmt:expr) => {{ < span class = "comment" > /* compiler built-in */< / span > }};
($fmt:expr, $($args:tt)*) => {{ < span class = "comment" > /* compiler built-in */< / span > }};
}
< span class = "keyword" > fn< / span > < span class = "function declaration" > main< / span > () {
< span class = "comment" > // from https://doc.rust-lang.org/std/fmt/index.html< / span >
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello"< / span > ); < span class = "comment" > // => "Hello"< / span >
2020-04-28 07:44:20 +00:00
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello, < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , < span class = "string_literal" > "world"< / span > ); < span class = "comment" > // => "Hello, world!"< / span >
< span class = "macro" > println!< / span > (< span class = "string_literal" > "The number is < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , < span class = "numeric_literal" > 1< / span > ); < span class = "comment" > // => "The number is 1"< / span >
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > ?< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , (< span class = "numeric_literal" > 3< / span > , < span class = "numeric_literal" > 4< / span > )); < span class = "comment" > // => "(3, 4)"< / span >
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "variable" > value< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , value=< span class = "numeric_literal" > 4< / span > ); < span class = "comment" > // => "4"< / span >
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , < span class = "numeric_literal" > 1< / span > , < span class = "numeric_literal" > 2< / span > ); < span class = "comment" > // => "1 2"< / span >
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "numeric_literal" > 0< / span > < span class = "numeric_literal" > 4< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , < span class = "numeric_literal" > 42< / span > ); < span class = "comment" > // => "0042" with leading zerosV< / span >
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "numeric_literal" > 1< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > < / span > < span class = "format_specifier" > {< / span > < span class = "numeric_literal" > 0< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , < span class = "numeric_literal" > 1< / span > , < span class = "numeric_literal" > 2< / span > ); < span class = "comment" > // => "2 1 1 2"< / span >
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "variable" > argument< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , argument = < span class = "string_literal" > "test"< / span > ); < span class = "comment" > // => "test"< / span >
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "variable" > name< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , < span class = "numeric_literal" > 1< / span > , name = < span class = "numeric_literal" > 2< / span > ); < span class = "comment" > // => "2 1"< / span >
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "variable" > a< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > < / span > < span class = "format_specifier" > {< / span > < span class = "variable" > c< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > < / span > < span class = "format_specifier" > {< / span > < span class = "variable" > b< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , a=< span class = "string_literal" > "a"< / span > , b=< span class = "char_literal" > 'b'< / span > , c=< span class = "numeric_literal" > 3< / span > ); < span class = "comment" > // => "a 3 b"< / span >
2020-05-30 16:35:11 +00:00
< span class = "macro" > println!< / span > (< span class = "string_literal" > "{{< / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > }}"< / span > , < span class = "numeric_literal" > 2< / span > ); < span class = "comment" > // => "{2}"< / span >
2020-04-28 07:44:20 +00:00
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "numeric_literal" > 5< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , < span class = "string_literal" > "x"< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "numeric_literal" > 1< / span > < span class = "format_specifier" > $< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , < span class = "string_literal" > "x"< / span > , < span class = "numeric_literal" > 5< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "numeric_literal" > 1< / span > < span class = "format_specifier" > :< / span > < span class = "numeric_literal" > 0< / span > < span class = "format_specifier" > $< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , < span class = "numeric_literal" > 5< / span > , < span class = "string_literal" > "x"< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "variable" > width< / span > < span class = "format_specifier" > $< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , < span class = "string_literal" > "x"< / span > , width = < span class = "numeric_literal" > 5< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > < < / span > < span class = "numeric_literal" > 5< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , < span class = "string_literal" > "x"< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > -< / span > < span class = "format_specifier" > < < / span > < span class = "numeric_literal" > 5< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , < span class = "string_literal" > "x"< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > ^< / span > < span class = "numeric_literal" > 5< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , < span class = "string_literal" > "x"< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > > < / span > < span class = "numeric_literal" > 5< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , < span class = "string_literal" > "x"< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > +< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , < span class = "numeric_literal" > 5< / span > );
2020-06-07 20:57:24 +00:00
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > #< / span > < span class = "variable" > x< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , < span class = "numeric_literal" > 27< / span > );
2020-04-28 07:44:20 +00:00
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "numeric_literal" > 0< / span > < span class = "numeric_literal" > 5< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , < span class = "numeric_literal" > 5< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "numeric_literal" > 0< / span > < span class = "numeric_literal" > 5< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , -< span class = "numeric_literal" > 5< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > #< / span > < span class = "numeric_literal" > 0< / span > < span class = "numeric_literal" > 10< / span > < span class = "variable" > x< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , < span class = "numeric_literal" > 27< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "numeric_literal" > 0< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > is < / span > < span class = "format_specifier" > {< / span > < span class = "numeric_literal" > 1< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > .< / span > < span class = "numeric_literal" > 5< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , < span class = "string_literal" > "x"< / span > , < span class = "numeric_literal" > 0.01< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "numeric_literal" > 1< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > is < / span > < span class = "format_specifier" > {< / span > < span class = "numeric_literal" > 2< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > .< / span > < span class = "numeric_literal" > 0< / span > < span class = "format_specifier" > $< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , < span class = "numeric_literal" > 5< / span > , < span class = "string_literal" > "x"< / span > , < span class = "numeric_literal" > 0.01< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "numeric_literal" > 0< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > is < / span > < span class = "format_specifier" > {< / span > < span class = "numeric_literal" > 2< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > .< / span > < span class = "numeric_literal" > 1< / span > < span class = "format_specifier" > $< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , < span class = "string_literal" > "x"< / span > , < span class = "numeric_literal" > 5< / span > , < span class = "numeric_literal" > 0.01< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > is < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > .< / span > < span class = "format_specifier" > *< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , < span class = "string_literal" > "x"< / span > , < span class = "numeric_literal" > 5< / span > , < span class = "numeric_literal" > 0.01< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > is < / span > < span class = "format_specifier" > {< / span > < span class = "numeric_literal" > 2< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > .< / span > < span class = "format_specifier" > *< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , < span class = "string_literal" > "x"< / span > , < span class = "numeric_literal" > 5< / span > , < span class = "numeric_literal" > 0.01< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > is < / span > < span class = "format_specifier" > {< / span > < span class = "variable" > number< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > .< / span > < span class = "variable" > prec< / span > < span class = "format_specifier" > $< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , < span class = "string_literal" > "x"< / span > , prec = < span class = "numeric_literal" > 5< / span > , number = < span class = "numeric_literal" > 0.01< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > , `< / span > < span class = "format_specifier" > {< / span > < span class = "variable" > name< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > .< / span > < span class = "format_specifier" > *< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > ` has 3 fractional digits"< / span > , < span class = "string_literal" > "Hello"< / span > , < span class = "numeric_literal" > 3< / span > , name=< span class = "numeric_literal" > 1234.56< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > , `< / span > < span class = "format_specifier" > {< / span > < span class = "variable" > name< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > .< / span > < span class = "format_specifier" > *< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > ` has 3 characters"< / span > , < span class = "string_literal" > "Hello"< / span > , < span class = "numeric_literal" > 3< / span > , name=< span class = "string_literal" > "1234.56"< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > , `< / span > < span class = "format_specifier" > {< / span > < span class = "variable" > name< / span > < span class = "format_specifier" > :< / span > < span class = "format_specifier" > > < / span > < span class = "numeric_literal" > 8< / span > < span class = "format_specifier" > .< / span > < span class = "format_specifier" > *< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > ` has 3 right-aligned characters"< / span > , < span class = "string_literal" > "Hello"< / span > , < span class = "numeric_literal" > 3< / span > , name=< span class = "string_literal" > "1234.56"< / span > );
2020-04-17 07:37:18 +00:00
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello {{}}"< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "{{ Hello"< / span > );
2020-04-22 13:28:35 +00:00
2020-04-28 07:44:20 +00:00
< span class = "macro" > println!< / span > (< span class = "string_literal" > r"Hello, < / span > < span class = "format_specifier" > {< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > !"< / span > , < span class = "string_literal" > "world"< / span > );
2020-04-22 13:28:35 +00:00
2020-06-17 13:27:13 +00:00
< span class = "comment" > // escape sequences< / span >
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello< / span > < span class = "escape_sequence" > \n< / span > < span class = "string_literal" > World"< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "escape_sequence" > \u{48}< / span > < span class = "escape_sequence" > \x65< / span > < span class = "escape_sequence" > \x6C< / span > < span class = "escape_sequence" > \x6C< / span > < span class = "escape_sequence" > \x6F< / span > < span class = "string_literal" > World"< / span > );
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "escape_sequence" > \x41< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , A = < span class = "numeric_literal" > 92< / span > );
2020-04-28 07:44:20 +00:00
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "variable" > ничоси< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , ничоси = < span class = "numeric_literal" > 92< / span > );
2020-04-17 07:37:18 +00:00
}< / code > < / pre >