2020-04-17 02:37:18 -05: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-02 17:49:09 -05:00
.operator.unsafe { color: #E28C14; }
2020-04-17 02:37:18 -05: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 11:40:52 -05:00
.bool_literal { color: #BFE6EB; }
2020-04-17 02:37:18 -05:00
.macro { color: #94BFF3; }
.module { color: #AFD8AF; }
.variable { color: #DCDCCC; }
2020-04-28 02:44:20 -05:00
.format_specifier { color: #CC696B; }
2020-04-17 02:37:18 -05:00
.mutable { text-decoration: underline; }
.keyword { color: #F0DFAF; font-weight: bold; }
.keyword.unsafe { color: #BC8383; font-weight: bold; }
.control { font-style: italic; }
< / style >
2020-05-10 10:08:54 -05:00
< pre > < code > < span class = "macro" > macro_rules!< / span > < span class = "macro declaration" > println< / span > {
2020-04-17 02:37:18 -05: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 10:08:54 -05:00
< span class = "macro" > macro_rules!< / span > < span class = "macro declaration" > format_args_nl< / span > {
2020-04-17 02:37:18 -05: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 02:44:20 -05: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 11:35:11 -05: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 02:44:20 -05: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 > );
< 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 = "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 = "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 02:37:18 -05: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 08:28:35 -05:00
2020-04-28 02:44:20 -05: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 08:28:35 -05:00
2020-04-28 02:44:20 -05:00
< span class = "macro" > println!< / span > (< span class = "string_literal" > "< / span > < span class = "format_specifier" > {< / span > < span class = "variable" > \x41< / span > < span class = "format_specifier" > }< / span > < span class = "string_literal" > "< / span > , A = < span class = "numeric_literal" > 92< / span > );
< 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 02:37:18 -05:00
}< / code > < / pre >