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; }
2020-06-22 09:28:07 -05:00
.documentation { color: #629755; }
2020-06-18 09:30:40 -05:00
.injected { opacity: 0.65 ; }
2020-04-17 02:37:18 -05:00
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
.string_literal { color: #CC9393; }
.field { color: #94BFF3; }
.function { color: #93E0E3; }
2020-06-08 08:23:03 -05:00
.function.unsafe { color: #BC8383; }
.operator.unsafe { color: #BC8383; }
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; }
2020-07-11 07:50:00 -05:00
.value_param { color: #DCDCCC; }
2020-04-17 02:37:18 -05:00
.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; }
2020-06-17 08:27:13 -05:00
.escape_sequence { color: #94BFF3; }
2020-04-17 02:37:18 -05:00
.keyword { color: #F0DFAF; font-weight: bold; }
.keyword.unsafe { color: #BC8383; font-weight: bold; }
.control { font-style: italic; }
2020-07-11 07:50:00 -05:00
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
2020-04-17 02:37:18 -05:00
< / style >
2020-06-23 08:17:53 -05:00
< pre > < code > < span class = "macro" > macro_rules!< / span > < span class = "macro declaration" > println< / span > {
($($arg:tt)*) => ({
$< span class = "keyword" > crate< / span > ::io::_print($< span class = "keyword" > crate< / span > ::format_args_nl!($($arg)*));
})
}
2020-04-17 02:37:18 -05:00
#[rustc_builtin_macro]
2020-06-23 08:17:53 -05:00
< span class = "macro" > macro_rules!< / span > < span class = "macro declaration" > format_args_nl< / span > {
($fmt:expr) => {{ < span class = "comment" > /* compiler built-in */< / span > }};
($fmt:expr, $($args:tt)*) => {{ < span class = "comment" > /* compiler built-in */< / span > }};
}
2020-04-17 02:37:18 -05:00
2020-06-23 08:17:53 -05:00
< span class = "keyword" > fn< / span > < span class = "function declaration" > main< / span > () {
2020-04-17 02:37:18 -05:00
< span class = "comment" > // from https://doc.rust-lang.org/std/fmt/index.html< / span >
2020-06-23 08:17:53 -05:00
< span class = "macro" > println!< / span > (< span class = "string_literal" > "Hello"< / span > ); < span class = "comment" > // => "Hello"< / 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" > !"< / 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 >
< 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 >
< 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 = "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 = "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 > );
< 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-06-23 08:17:53 -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-06-17 08:27:13 -05:00
< span class = "comment" > // escape sequences< / span >
2020-06-23 08:17:53 -05:00
< 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 > );
2020-06-17 08:27:13 -05:00
2020-06-23 08:17:53 -05:00
< 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 > );
< 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 > );
}< / code > < / pre >