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

Update documentation for #57 - string literals in attributes #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ The precise Unicode conversions are as defined by [`str::to_lowercase`] and

<br>

## Pasting documentation strings
## Pasting string literals into attributes

Within the `paste!` macro, arguments to a #\[doc ...\] attribute are implicitly
concatenated together to form a coherent documentation string.
Within the `paste!` macro, if there are two or more arguments to an attribute they are implicitly
concatenated together to form a string literal.

```rust
use paste::paste;
Expand All @@ -129,14 +129,18 @@ macro_rules! method_new {
($ret:ident) => {
paste! {
#[doc = "Create a new `" $ret "` object."]
#[cfg(feature = "" $ret:snake)]
pub fn new() -> $ret { todo!() }
}
};
}

pub struct Paste {}

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

<br>
Expand Down
22 changes: 13 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,30 @@
//!
//! <br>
//!
//! # Pasting documentation strings
//!
//! Within the `paste!` macro, arguments to a #\[doc ...\] attribute are
//! implicitly concatenated together to form a coherent documentation string.
//!
//! ## Pasting string literals into attributes
//!
//! Within the `paste!` macro, if there are two or more arguments to an attribute they are implicitly
//! concatenated together to form a string literal.
//!
//! ```
//! use paste::paste;
//!
//!
//! macro_rules! method_new {
//! ($ret:ident) => {
//! paste! {
//! #[doc = "Create a new `" $ret "` object."]
//! #[cfg(feature = "" $ret:snake)]
//! pub fn new() -> $ret { todo!() }
//! }
//! };
//! }
//!
//!
//! pub struct Paste {}
//!
//! method_new!(Paste); // expands to #[doc = "Create a new `Paste` object"]
//!
//! // expands to:
//! // #[doc = "Create a new `Paste` object."]
//! // #[cfg(feature = "paste")]
//! method_new!(Paste);
//! ```

#![doc(html_root_url = "https://docs.rs/paste/1.0.15")]
Expand Down