std::include - Rust
Description: API documentation for the Rust `include` macro in crate `std`.
Keywords: rust, rustlang, rust-lang, include

# Macro std::include 1.0.0 [−] [src]

    macro_rules! include {
        ($file:expr) => { ... };
    }

Parse a file as an expression or an item according to the context.

The file is located relative to the current file (similarly to how modules are found).

Using this macro is often a bad idea, because if the file is parsed as an expression, it is going to be placed in the surrounding code unhygienically. This could result in variables or functions being different from what the file expected if there are variables or functions that have the same name in the current file.

# Examples

Assume there are two files in the same directory with the following contents:

File 'monkeys.in':

ⓘThis example is not tested

    ['🙈', '🙊', '🙉']
        .iter()
        .cycle()
        .take(6)
        .collect::<String>()Run

File 'main.rs':

ⓘThis example is not tested

    fn main() {
        let my_string = include!("monkeys.in");
        assert_eq!("🙈🙊🙉🙈🙊🙉", my_string);
        println!("{}", my_string);
    }Run

Compiling 'main.rs' and running the resulting binary will print "🙈🙊🙉🙈🙊🙉".

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
↑
  Move up in search results
↓
  Move down in search results
↹
  Switch tab
⏎
  Go to active search result
+ / -
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)