Skip to content

Commit a91e8a2

Browse files
Rollup merge of rust-lang#43819 - frewsxcv:frewsxcv-include, r=QuietMisdreavus
Improve doc examples for `include*` macros.
2 parents bc6659a + 8d0d2a5 commit a91e8a2

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed

β€Žsrc/libstd/macros.rs

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,26 @@ pub mod builtin {
461461
///
462462
/// # Examples
463463
///
464+
/// Assume there are two files in the same directory with the following
465+
/// contents:
466+
///
467+
/// File 'spanish.in':
468+
///
469+
/// ```text
470+
/// adiΓ³s
471+
/// ```
472+
///
473+
/// File 'main.rs':
474+
///
464475
/// ```ignore (cannot-doctest-external-file-dependency)
465-
/// let secret_key = include_str!("secret-key.ascii");
476+
/// fn main() {
477+
/// let my_str = include_str!("spanish.in");
478+
/// assert_eq!(my_str, "adiΓ³s\n");
479+
/// print!("{}", my_str);
480+
/// }
466481
/// ```
482+
///
483+
/// Compiling 'main.rs' and running the resulting binary will print "adiΓ³s".
467484
#[stable(feature = "rust1", since = "1.0.0")]
468485
#[macro_export]
469486
macro_rules! include_str { ($file:expr) => ({ /* compiler built-in */ }) }
@@ -478,9 +495,26 @@ pub mod builtin {
478495
///
479496
/// # Examples
480497
///
498+
/// Assume there are two files in the same directory with the following
499+
/// contents:
500+
///
501+
/// File 'spanish.in':
502+
///
503+
/// ```text
504+
/// adiΓ³s
505+
/// ```
506+
///
507+
/// File 'main.rs':
508+
///
481509
/// ```ignore (cannot-doctest-external-file-dependency)
482-
/// let secret_key = include_bytes!("secret-key.bin");
510+
/// fn main() {
511+
/// let bytes = include_bytes!("spanish.in");
512+
/// assert_eq!(bytes, b"adi\xc3\xb3s\n");
513+
/// print!("{}", String::from_utf8_lossy(bytes));
514+
/// }
483515
/// ```
516+
///
517+
/// Compiling 'main.rs' and running the resulting binary will print "adiΓ³s".
484518
#[stable(feature = "rust1", since = "1.0.0")]
485519
#[macro_export]
486520
macro_rules! include_bytes { ($file:expr) => ({ /* compiler built-in */ }) }
@@ -545,23 +579,28 @@ pub mod builtin {
545579
/// Assume there are two files in the same directory with the following
546580
/// contents:
547581
///
548-
/// File 'my_str.in':
582+
/// File 'monkeys.in':
549583
///
550584
/// ```ignore (only-for-syntax-highlight)
551-
/// "Hello World!"
585+
/// ['πŸ™ˆ', 'πŸ™Š', 'πŸ™‰']
586+
/// .iter()
587+
/// .cycle()
588+
/// .take(6)
589+
/// .collect::<String>()
552590
/// ```
553591
///
554592
/// File 'main.rs':
555593
///
556594
/// ```ignore (cannot-doctest-external-file-dependency)
557595
/// fn main() {
558-
/// let my_str = include!("my_str.in");
559-
/// println!("{}", my_str);
596+
/// let my_string = include!("monkeys.in");
597+
/// assert_eq!("πŸ™ˆπŸ™ŠπŸ™‰πŸ™ˆπŸ™ŠπŸ™‰", my_string);
598+
/// println!("{}", my_string);
560599
/// }
561600
/// ```
562601
///
563-
/// Compiling 'main.rs' and running the resulting binary will print "Hello
564-
/// World!".
602+
/// Compiling 'main.rs' and running the resulting binary will print
603+
/// "πŸ™ˆπŸ™ŠπŸ™‰πŸ™ˆπŸ™ŠπŸ™‰".
565604
#[stable(feature = "rust1", since = "1.0.0")]
566605
#[macro_export]
567606
macro_rules! include { ($file:expr) => ({ /* compiler built-in */ }) }

0 commit comments

Comments
Β (0)