include_asciidoc!() { /* proc-macro */ }Expand description
Include code from within a source block in an AsciiDoc file.
Two arguments are required: a file path relative to the current source file, and an id defined within the source block attributes as shown below.
All AsciiDoc source blocks with delimited listing blocks are supported.
ยงExamples
Consider the following source block in a crate README.adoc AsciiDoc file:
[,rust,id="example"]
----
let m = example()?;
assert_eq!(format!("{m:?}"), r#"Model { name: "example" }"#);
----We can include this code block in our 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_asciidoc!("README.adoc", "example");
Ok(())
}