diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-08-13 11:03:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-13 11:03:11 +0200 |
| commit | a91e8a2053d0136c479a39bec6368757bcfa4af9 (patch) | |
| tree | 5b05e925a4a62a78efc1042ce1fdc02f091ace33 /src/libstd | |
| parent | bc6659a8fef000c96665f6ba8d6ddcd1ef89623b (diff) | |
| parent | 8d0d2a572939b2fba74a59db2de0ad4e30484b43 (diff) | |
| download | rust-a91e8a2053d0136c479a39bec6368757bcfa4af9.tar.gz rust-a91e8a2053d0136c479a39bec6368757bcfa4af9.zip | |
Rollup merge of #43819 - frewsxcv:frewsxcv-include, r=QuietMisdreavus
Improve doc examples for `include*` macros.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/macros.rs | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 5e88a46ecc3..c426bf8086e 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -461,9 +461,26 @@ pub mod builtin { /// /// # Examples /// + /// Assume there are two files in the same directory with the following + /// contents: + /// + /// File 'spanish.in': + /// + /// ```text + /// adiós + /// ``` + /// + /// File 'main.rs': + /// /// ```ignore (cannot-doctest-external-file-dependency) - /// let secret_key = include_str!("secret-key.ascii"); + /// fn main() { + /// let my_str = include_str!("spanish.in"); + /// assert_eq!(my_str, "adiós\n"); + /// print!("{}", my_str); + /// } /// ``` + /// + /// Compiling 'main.rs' and running the resulting binary will print "adiós". #[stable(feature = "rust1", since = "1.0.0")] #[macro_export] macro_rules! include_str { ($file:expr) => ({ /* compiler built-in */ }) } @@ -478,9 +495,26 @@ pub mod builtin { /// /// # Examples /// + /// Assume there are two files in the same directory with the following + /// contents: + /// + /// File 'spanish.in': + /// + /// ```text + /// adiós + /// ``` + /// + /// File 'main.rs': + /// /// ```ignore (cannot-doctest-external-file-dependency) - /// let secret_key = include_bytes!("secret-key.bin"); + /// fn main() { + /// let bytes = include_bytes!("spanish.in"); + /// assert_eq!(bytes, b"adi\xc3\xb3s\n"); + /// print!("{}", String::from_utf8_lossy(bytes)); + /// } /// ``` + /// + /// Compiling 'main.rs' and running the resulting binary will print "adiós". #[stable(feature = "rust1", since = "1.0.0")] #[macro_export] macro_rules! include_bytes { ($file:expr) => ({ /* compiler built-in */ }) } @@ -545,23 +579,28 @@ pub mod builtin { /// Assume there are two files in the same directory with the following /// contents: /// - /// File 'my_str.in': + /// File 'monkeys.in': /// /// ```ignore (only-for-syntax-highlight) - /// "Hello World!" + /// ['🙈', '🙊', '🙉'] + /// .iter() + /// .cycle() + /// .take(6) + /// .collect::<String>() /// ``` /// /// File 'main.rs': /// /// ```ignore (cannot-doctest-external-file-dependency) /// fn main() { - /// let my_str = include!("my_str.in"); - /// println!("{}", my_str); + /// let my_string = include!("monkeys.in"); + /// assert_eq!("🙈🙊🙉🙈🙊🙉", my_string); + /// println!("{}", my_string); /// } /// ``` /// - /// Compiling 'main.rs' and running the resulting binary will print "Hello - /// World!". + /// Compiling 'main.rs' and running the resulting binary will print + /// "🙈🙊🙉🙈🙊🙉". #[stable(feature = "rust1", since = "1.0.0")] #[macro_export] macro_rules! include { ($file:expr) => ({ /* compiler built-in */ }) } |
