include_textile

Macro include_textile 

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

Include code from within a code block in a Textile file.

All Textile 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 code block in a crate README.textile Textile file:

bc(rust#example). let m = example()?;
assert_eq!(format!("{m:?}"), r#"Model { name: "example" }"#);

In Rust documentation comments, we can use # line to hide setup code. That’s not possible in Textile, 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_textile!("README.textile", "example");
    Ok(())
}