include_org

Macro include_org 

Source
include_org!() { /* proc-macro */ }
Available on crate feature org only.
Expand description

Include code from within a source block in an Org file.

All Org source code blocks are supported.

§Arguments

  • path (Required) Path relative to the crate root directory.
  • name (Required) Name of the code fence to include.
  • scope Include the snippet in braces { .. }.
  • relative (Requires rustc 1.88 or newer) Path is relative to the source file calling the macro.

§Examples

Consider the following source block in a crate README.org Org file:

#+NAME: example
#+BEGIN_SRC rust
let m = example()?;
assert_eq!(format!("{m:?}"), r#"Model { name: "example" }"#);
#+END_SRC

In Rust documentation comments, we can use # line to hide setup code. That’s not possible in Org, so we can include only the code we want to demonstrate; however, we can still compile and even run it in Rust tests:

struct Model {
    name: String,
}

fn example() -> Result<Model, Box<dyn std::error::Error>> {
    Ok(Model { name: "example".into() })
}

#[test]
fn test_example() -> Result<(), Box<dyn std::error::Error>> {
    include_org!("README.org", "example");
    Ok(())
}