Skip to content

Commit

Permalink
Document RUSTFMT environment variable (rust-lang#4464)
Browse files Browse the repository at this point in the history
* Document RUSTFMT env var

* Move documentation up

* Apply suggestions from code review

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>

* Fix accedental removal

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
# Conflicts:
#	README.md
  • Loading branch information
MonliH authored and calebcartwright committed Oct 30, 2021
1 parent a24ed3c commit a4d7011
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ read data from stdin. Alternatively, you can use `cargo fmt` to format all
binary and library targets of your crate.

You can run `rustfmt --help` for information about available arguments.
The easiest way to run rustfmt against a project is with `cargo fmt`. `cargo fmt` works on both
single-crate projects and [cargo workspaces](https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html).
Please see `cargo fmt --help` for usage information.

You can specify the path to your own `rustfmt` binary for cargo to use by setting the`RUSTFMT`
environment variable. This was added in v1.4.22, so you must have this version or newer to leverage this feature (`cargo fmt --version`)

### Running `rustfmt` directly

To format individual files or arbitrary codes from stdin, the `rustfmt` binary should be used. Some
examples follow:

- `rustfmt lib.rs main.rs` will format "lib.rs" and "main.rs" in place
- `rustfmt` will read a code from stdin and write formatting to stdout
- `echo "fn main() {}" | rustfmt` would emit "fn main() {}".

For more information, including arguments and emit options, see `rustfmt --help`.

### Verifying code is formatted

When running with `--check`, Rustfmt will exit with `0` if Rustfmt would not
make any formatting changes to the input, and `1` if Rustfmt would make changes.
Expand Down

0 comments on commit a4d7011

Please sign in to comment.