Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
Document #[doc ...] pasting
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 26, 2020
1 parent 40db57a commit 0c8b261
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,28 @@ The precise Unicode conversions are as defined by [`str::to_lowercase`] and

<br>

## Pasting documentation strings

Within the `paste!` macro, arguments to a #\[doc ...\] attribute are implicitly
concatenated together to form a coherent documentation string.

```rust
use paste::paste;

macro_rules! method_new {
($ret:ident) => {
paste! {
#[doc = "Create a new `" $ret "` object."]
pub fn new() -> $ret { todo!() }
}
};
}

method_new!(Paste); // expands to #[doc = "Create a new `Paste` object"]
```

<br>

#### License

<sup>
Expand Down
23 changes: 23 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@
//!
//! [`str::to_lowercase`]: https://doc.rust-lang.org/std/primitive.str.html#method.to_lowercase
//! [`str::to_uppercase`]: https://doc.rust-lang.org/std/primitive.str.html#method.to_uppercase
//!
//! <br>
//!
//! # Pasting documentation strings
//!
//! Within the `paste!` macro, arguments to a #\[doc ...\] attribute are
//! implicitly concatenated together to form a coherent documentation string.
//!
//! ```
//! use paste::paste;
//!
//! macro_rules! method_new {
//! ($ret:ident) => {
//! paste! {
//! #[doc = "Create a new `" $ret "` object."]
//! pub fn new() -> $ret { todo!() }
//! }
//! };
//! }
//!
//! # struct Paste;
//! method_new!(Paste); // expands to #[doc = "Create a new `Paste` object"]
//! ```

#![allow(clippy::needless_doctest_main)]

Expand Down

0 comments on commit 0c8b261

Please sign in to comment.