include_asciidoc!() { /* proc-macro */ }Available on crate feature
asciidoc only.Expand description
Include code from within a source block in an AsciiDoc file.
All AsciiDoc source blocks with delimited listing blocks are supported.
§Arguments
path(Required) Path relative to the crate root directory.name(Required) Name of the code fence to include.scopeInclude 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.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(())
}