devela::code::util

Macro include_from

Source
macro_rules! include_from {
    ($module_name:ident) => { ... };
    ($module_path_str:literal) => { ... };
}
Expand description

Includes a Rust source file relative to the project’s directory.

The contents of the specified file are inserted into the current file at the location of the macro invocation. This allows you to reuse code from other files without creating separate modules.

§Usage

  • To include a file relative to the project’s directory:
include_from!("src/helper.rs");
  • To include a file using its module name (relative to the project’s directory):
include_from!(helper); // Resolves to "helper.rs" in the project's root.
  • When using cargo-script, the path is relative to the script’s directory:
#!/usr/bin/env -S cargo +nightly -Zscript
include_from!(utils);

See also mod_from!.