include_textile!() { /* proc-macro */ }Expand description
Include code from within a code block in a Textile file.
Two arguments are required: a file path relative to the current source file, and an id defined within the code block as shown below.
All Textile code blocks are supported.
§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(())
}