From ea6f0f060c05da71761ed1cfce5763ddcbe962be Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Fri, 11 Aug 2017 23:45:48 -0400 Subject: [PATCH 1/3] Demonstrate `include!` with Rust code, not just a string slice literal. --- src/libstd/macros.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 5e88a46ecc343..d3e367b815acb 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -545,23 +545,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::() /// ``` /// /// 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 */ }) } From 446ff0d529ff0d3747bcf11b36dd7c60e6a900d5 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 12 Aug 2017 00:22:49 -0400 Subject: [PATCH 2/3] Add complete doc example for `include_bytes!`. --- src/libstd/macros.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index d3e367b815acb..bc170f8ce1bed 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -478,9 +478,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 */ }) } From 8d0d2a572939b2fba74a59db2de0ad4e30484b43 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 12 Aug 2017 00:25:49 -0400 Subject: [PATCH 3/3] Add complete doc example for `include_str!`. --- src/libstd/macros.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index bc170f8ce1bed..c426bf8086eef 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 */ }) }