Skip to content

Commit 95eab94

Browse files
Merge pull request #882 from ehuss/1.54-path-attribute
Remove `#[path]` example from 1.54 blog post.
2 parents 3382816 + 7f8dbf0 commit 95eab94

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

posts/2021-07-29-Rust-1.54.0.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,29 @@ Rust 1.54 supports invoking function-like macros inside attributes. Function-lik
3333
#![doc = include_str!("README.md")]
3434
```
3535

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

3839
```rust
39-
#[path = concat!(env!("OUT_DIR"), "/generated.rs")]
40-
mod generated;
40+
macro_rules! make_function {
41+
($name:ident, $value:expr) => {
42+
#[doc = concat!("The `", stringify!($name), "` example.")]
43+
///
44+
/// # Example
45+
///
46+
/// ```
47+
#[doc = concat!(
48+
"assert_eq!(", module_path!(), "::", stringify!($name), "(), ",
49+
stringify!($value), ");")
50+
]
51+
/// ```
52+
pub fn $name() -> i32 {
53+
$value
54+
}
55+
};
56+
}
57+
58+
make_function! {func_name, 123}
4159
```
4260

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

0 commit comments

Comments
 (0)