Skip to content

Commit

Permalink
Merge pull request #882 from ehuss/1.54-path-attribute
Browse files Browse the repository at this point in the history
Remove `#[path]` example from 1.54 blog post.
  • Loading branch information
Mark-Simulacrum committed Aug 3, 2021
2 parents 3382816 + 7f8dbf0 commit 95eab94
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions posts/2021-07-29-Rust-1.54.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,29 @@ Rust 1.54 supports invoking function-like macros inside attributes. Function-lik
#![doc = include_str!("README.md")]
```

Macros can be nested inside the attribute as well, for example to include content generated by a build script:
Macros can be nested inside the attribute as well.
For example, the `concat!` macro can be used to construct a doc comment from within a macro that uses `stringify!` to include substitutions:

```rust
#[path = concat!(env!("OUT_DIR"), "/generated.rs")]
mod generated;
macro_rules! make_function {
($name:ident, $value:expr) => {
#[doc = concat!("The `", stringify!($name), "` example.")]
///
/// # Example
///
/// ```
#[doc = concat!(
"assert_eq!(", module_path!(), "::", stringify!($name), "(), ",
stringify!($value), ");")
]
/// ```
pub fn $name() -> i32 {
$value
}
};
}

make_function! {func_name, 123}
```

Read [here](https://github.com/rust-lang/rust/pull/83366) for more details.
Expand Down

0 comments on commit 95eab94

Please sign in to comment.