From 8d0d2a572939b2fba74a59db2de0ad4e30484b43 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 12 Aug 2017 00:25:49 -0400 Subject: [PATCH] Add complete doc example for `include_str!`. --- src/libstd/macros.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index bc170f8ce1be..c426bf8086ee 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -461,9 +461,26 @@ macro_rules! stringify { ($t:tt) => ({ /* compiler built-in */ }) } /// /// # Examples /// - /// ```ignore (cannot-doctest-external-file-dependency) - /// let secret_key = include_str!("secret-key.ascii"); + /// 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) + /// 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 */ }) }