Skip to content

Commit

Permalink
Replace the term custom derive
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 11, 2019
1 parent 36da292 commit 80d2a3b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ of Rust source code.
Currently this library is geared toward use in Rust procedural macros, but
contains some APIs that may be useful more generally.

[custom derive]: https://github.com/rust-lang/rfcs/blob/master/text/1681-macros-1.1.md

- **Data structures** — Syn provides a complete syntax tree that can represent
any valid Rust source code. The syntax tree is rooted at [`syn::File`] which
represents a full source file, but there are other entry points that may be
useful to procedural macros including [`syn::Item`], [`syn::Expr`] and
[`syn::Type`].

- **Custom derives** — Of particular interest to custom derives is
[`syn::DeriveInput`] which is any of the three legal input items to a derive
macro. An example below shows using this type in a library that can derive
implementations of a trait of your own.
- **Derives** — Of particular interest to derive macros is [`syn::DeriveInput`]
which is any of the three legal input items to a derive macro. An example
below shows using this type in a library that can derive implementations of a
user-defined trait.

- **Parsing** — Parsing in Syn is built around [parser functions] with the
signature `fn(ParseStream) -> Result<T>`. Every syntax tree node defined by
Expand Down Expand Up @@ -59,9 +57,9 @@ channel.*

[*Release notes*](https://github.com/dtolnay/syn/releases)

## Example of a custom derive
## Example of a derive macro

The canonical custom derive using Syn looks like this. We write an ordinary Rust
The canonical derive macro using Syn looks like this. We write an ordinary Rust
function tagged with a `proc_macro_derive` attribute and the name of the trait
we are deriving. Any time that derive appears in the user's code, the Rust
compiler passes their data structure as tokens into our macro. We get to execute
Expand Down Expand Up @@ -101,10 +99,10 @@ pub fn my_macro(input: TokenStream) -> TokenStream {
}
```

The [`heapsize`] example directory shows a complete working Macros 1.1
implementation of a custom derive. It works on any Rust compiler 1.15+. The
example derives a `HeapSize` trait which computes an estimate of the amount of
heap memory owned by a value.
The [`heapsize`] example directory shows a complete working implementation of a
derive macro. It works on any Rust compiler 1.31+. The example derives a
`HeapSize` trait which computes an estimate of the amount of heap memory owned
by a value.

[`heapsize`]: examples/heapsize

Expand All @@ -115,7 +113,7 @@ pub trait HeapSize {
}
```

The custom derive allows users to write `#[derive(HeapSize)]` on data structures
The derive macro allows users to write `#[derive(HeapSize)]` on data structures
in their program.

```rust
Expand Down Expand Up @@ -219,7 +217,7 @@ compile time for the most common use cases. The following features are
available.

- **`derive`** *(enabled by default)* — Data structures for representing the
possible input to a custom derive, including structs and enums and types.
possible input to a derive macro, including structs and enums and types.
- **`full`** — Data structures for representing the syntax tree of all valid
Rust source code, including items and expressions.
- **`parsing`** *(enabled by default)* — Ability to parse input tokens into a
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ debug representation of the syntax tree.

### [`heapsize`](heapsize)

A complete working implementation of a custom derive. Works on any Rust compiler
A complete working implementation of a derive macro. Works on any Rust compiler
1.15+.

### [`lazy-static`](lazy-static)
Expand Down
6 changes: 3 additions & 3 deletions examples/heapsize/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
A complete working implementation of a custom derive. Written in Rust 2018 style
A complete working implementation of a derive macro. Written in Rust 2018 style
but otherwise works on any Rust compiler 1.15+.

- [`heapsize/src/lib.rs`](heapsize/src/lib.rs)
Expand All @@ -15,7 +15,7 @@ pub trait HeapSize {
}
```

The custom derive allows users to write `#[derive(HeapSize)]` on data structures
The derive macro allows users to write `#[derive(HeapSize)]` on data structures
in their program.

```rust
Expand All @@ -28,7 +28,7 @@ struct Demo<'a, T: ?Sized> {
}
```

The trait impl generated by the custom derive here would look like:
The trait impl generated by the derive macro here would look like:

```rust
impl<'a, T: ?Sized + heapsize::HeapSize> heapsize::HeapSize for Demo<'a, T> {
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
//! entry points that may be useful to procedural macros including
//! [`syn::Item`], [`syn::Expr`] and [`syn::Type`].
//!
//! - **Custom derives** — Of particular interest to custom derives is
//! - **Derives** — Of particular interest to derive macros is
//! [`syn::DeriveInput`] which is any of the three legal input items to a
//! derive macro. An example below shows using this type in a library that can
//! derive implementations of a trait of your own.
//! derive implementations of a user-defined trait.
//!
//! - **Parsing** — Parsing in Syn is built around [parser functions] with the
//! signature `fn(ParseStream) -> Result<T>`. Every syntax tree node defined
Expand All @@ -40,9 +40,9 @@
//!
//! <br>
//!
//! # Example of a custom derive
//! # Example of a derive macro
//!
//! The canonical custom derive using Syn looks like this. We write an ordinary
//! The canonical derive macro using Syn looks like this. We write an ordinary
//! Rust function tagged with a `proc_macro_derive` attribute and the name of
//! the trait we are deriving. Any time that derive appears in the user's code,
//! the Rust compiler passes their data structure as tokens into our macro. We
Expand Down Expand Up @@ -85,10 +85,10 @@
//! }
//! ```
//!
//! The [`heapsize`] example directory shows a complete working Macros 1.1
//! implementation of a custom derive. It works on any Rust compiler 1.15+.
//! The example derives a `HeapSize` trait which computes an estimate of the
//! amount of heap memory owned by a value.
//! The [`heapsize`] example directory shows a complete working implementation
//! of a derive macro. It works on any Rust compiler 1.31+. The example derives
//! a `HeapSize` trait which computes an estimate of the amount of heap memory
//! owned by a value.
//!
//! [`heapsize`]: https://github.com/dtolnay/syn/tree/master/examples/heapsize
//!
Expand All @@ -99,7 +99,7 @@
//! }
//! ```
//!
//! The custom derive allows users to write `#[derive(HeapSize)]` on data
//! The derive macro allows users to write `#[derive(HeapSize)]` on data
//! structures in their program.
//!
//! ```
Expand Down Expand Up @@ -223,7 +223,7 @@
//! are available.
//!
//! - **`derive`** *(enabled by default)* — Data structures for representing the
//! possible input to a custom derive, including structs and enums and types.
//! possible input to a derive macro, including structs and enums and types.
//! - **`full`** — Data structures for representing the syntax tree of all valid
//! Rust source code, including items and expressions.
//! - **`parsing`** *(enabled by default)* — Ability to parse input tokens into
Expand Down

0 comments on commit 80d2a3b

Please sign in to comment.