Skip to content

Commit a4d7011

Browse files
Document RUSTFMT environment variable (#4464)
* Document RUSTFMT env var * Move documentation up * Apply suggestions from code review Co-authored-by: Caleb Cartwright <[email protected]> * Fix accedental removal Co-authored-by: Caleb Cartwright <[email protected]> # Conflicts: # README.md
1 parent a24ed3c commit a4d7011

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,25 @@ read data from stdin. Alternatively, you can use `cargo fmt` to format all
102102
binary and library targets of your crate.
103103

104104
You can run `rustfmt --help` for information about available arguments.
105+
The easiest way to run rustfmt against a project is with `cargo fmt`. `cargo fmt` works on both
106+
single-crate projects and [cargo workspaces](https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html).
107+
Please see `cargo fmt --help` for usage information.
108+
109+
You can specify the path to your own `rustfmt` binary for cargo to use by setting the`RUSTFMT`
110+
environment variable. This was added in v1.4.22, so you must have this version or newer to leverage this feature (`cargo fmt --version`)
111+
112+
### Running `rustfmt` directly
113+
114+
To format individual files or arbitrary codes from stdin, the `rustfmt` binary should be used. Some
115+
examples follow:
116+
117+
- `rustfmt lib.rs main.rs` will format "lib.rs" and "main.rs" in place
118+
- `rustfmt` will read a code from stdin and write formatting to stdout
119+
- `echo "fn main() {}" | rustfmt` would emit "fn main() {}".
120+
121+
For more information, including arguments and emit options, see `rustfmt --help`.
122+
123+
### Verifying code is formatted
105124

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

0 commit comments

Comments
 (0)