commit | 76cd60a0275f085ec1f379324b0314da1902c431 | [log] [tgz] |
---|---|---|
author | Travis Cross <tc@traviscross.com> | Sun Oct 05 08:02:14 2025 +0000 |
committer | Travis Cross <tc@traviscross.com> | Sun Oct 05 08:22:48 2025 +0000 |
tree | 6bd5ab9137fbb3379a3c6f644c6d1b19d4b0878d | |
parent | 5acc59fe14a31c268576b1e9af07c7ec66827a4a [diff] |
Revise extending tuple struct constructor examples The example for the tuple enum variant constructor should go above the example that already uses a tuple enum variant constructor in a nested manner. This also matches the order in the list of extending expressions above -- the list items for tuple struct constructors and tuple enum variant constructors come after tuple expressions and before block expressions. For demonstrating a tuple enum variant constructor, it's better to use `Some(_)` than to define one; `Option<T>` is well known enough. For the tuple struct that we need to define, let's use a short name like `W<T>` here rather than `TupleStruct<T>` (and show its definition). When I see a name like `TupleStruct`, it takes me a moment to confirm it's just a name and not more than that. We use this `W<T>(T)` "wrapper" tuple struct definition elsewhere in the Reference. As a wording matter, we say "argument to" rather than "argument of". Similarly, something isn't an argument to a tuple struct but an argument to the tuple struct constructor, so let's say that.
This document is the primary reference for the Rust programming language.
First, ensure that you have a recent copy of the nightly Rust compiler installed, as this is needed in order to run the tests:
rustup toolchain install nightly
Now, ensure you have mdbook
installed, as this is needed in order to build the Reference:
cargo install --locked mdbook
To build the Reference, first clone the project:
git clone https://github.com/rust-lang/reference.git
(Alternatively, if you don't want to use git
, download a ZIP file of the project, extract it using your preferred tool, and rename the top-level directory to reference
.)
Now change your current directory to the working directory:
cd reference
To test all of the code examples in the Reference, run:
mdbook test
For authors, consider using the server functionality which supports automatic reload.
To build the Reference locally (in book/
) and open it in a web browser, run:
SPEC_RELATIVE=0 mdbook build --open
This will open a browser with a websocket live-link to automatically reload whenever the source is updated.
You can also use mdbook's live webserver option, which will automatically rebuild the book and reload your web browser whenever a source file is modified:
SPEC_RELATIVE=0 mdbook serve --open
SPEC_RELATIVE
The SPEC_RELATIVE=0
environment variable makes links to the standard library go to https://doc.rust-lang.org/ instead of being relative, which is useful when viewing locally since you normally don't have a copy of the standard library.
The published site at https://doc.rust-lang.org/reference/ (or local docs using rustup doc
) does not set this, which means it will use relative links which supports offline viewing and links to the correct version (for example, links in https://doc.rust-lang.org/1.81.0/reference/ will stay within the 1.81.0 directory).
SPEC_DENY_WARNINGS
The SPEC_DENY_WARNINGS=1
environment variable will turn all warnings generated by mdbook-spec
to errors. This is used in CI to ensure that there aren't any problems with the book content.
SPEC_RUST_ROOT
The SPEC_RUST_ROOT
can be used to point to the directory of a checkout of https://github.com/rust-lang/rust. This is used by the test-linking feature so that it can find tests linked to reference rules. If this is not set, then the tests won't be linked.