Skip to content

Commit

Permalink
📝 Updated README with new rustfmt options
Browse files Browse the repository at this point in the history
Signed-off-by: Luke Carr <luke@subtale.com>
  • Loading branch information
lukecarr committed May 11, 2023
1 parent 2213fb0 commit 6db1cd1
Showing 1 changed file with 144 additions and 0 deletions.
144 changes: 144 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,69 @@ Some of these settings are set to their default values; this is intentional to e

This is a required option because some of the below settings are considered "unstable" by rustfmt.

### `combine_control_expr = false`

Separates control expression from their function calls:

```rs
fn example() {
// If
foo!(
if x {
foo();
} else {
bar();
}
);

// IfLet
foo!(
if let Some(..) = x {
foo();
} else {
bar();
}
);
}
```

### `condense_wildcard_suffixes = true`

Replaces consecutive underscore variables with a single `..` within tuple patterns:

```rs
let (lorem, ipsum, _, _) = (1, 2, 3, 4);
// becomes
let (lorem, ipsum, ..) = (1, 2, 3, 4);
```

### `fn_single_line = true`

Puts single-expression functions on a single line:

```rs
fn lorem() -> usize { 42 }
```

### `format_code_in_doc_comments = true`

Formats code snippets in doc comments.

### `format_macro_matchers = true`

Formats metavariables in macro declarations:

```rs
macro_rules! foo {
($a:ident : $b:ty) => {
$a(42): $b;
};
($a:ident $b:ident $c:ident) => {
$a = $b + $c;
};
}
```

### `group_imports = "StdExternalCrate"`

Reorganizes imports into three distinct groups:
Expand All @@ -41,6 +104,10 @@ use super::update::convert_publish_payload;
use crate::models::Event;
```

### `hex_literal_case = "Upper"`

Forces uppercase hex literals.

### `imports_granularity = "Crate"`

Merges imports from the same crate into a single `use` statement.
Expand Down Expand Up @@ -72,6 +139,49 @@ use foo::{
};
```

### `match_block_trailing_comma = true`

Puts a trailing comma after a block-based match arm:

```rs
match lorem {
Lorem::Ipsum => {
println!("ipsum");
},
Lorem::Dolor => println!("dolor"),
}
```

### `normalize_comments = true`

Converts `/* */` comments to `//` comments where possible.

### `normalize_doc_attributes = true`

Converts `#[!doc = "..." ]` attributes to `///` comments where possible.

### `reorder_impl_items = true`

Reorders impl items. `type` and `const` are grouped together, then macros and functions:

```rs
impl Iterator for Dummy {
fn next(&mut self) -> Option<Self::Item> {
None
}

type Item = i32;
}
// becomes
impl Iterator for Dummy {
type Item = i32;

fn next(&mut self) -> Option<Self::Item> {
None
}
}
```

### `reorder_imports = true`

Ensures that imports and extern crate statements are sorted alphabetically (in groups).
Expand All @@ -83,5 +193,39 @@ use lorem;
use sit;
```

### `use_field_init_shorthand = true`

Uses the field init shorthand where possible:

```rs
fn main() {
let x = 1;
let y = 2;
let z = 3;
let a = Foo { x: x, y: y, z: z };
}
// becomes
fn main() {
let x = 1;
let y = 2;
let z = 3;
let a = Foo { x, y, z };
}
```

### `use_try_shorthand = true`

Replaces use of the `try!` macro with the `?` shorthand:

```rs
try!(ipsum.map(|dolor| dolor.sit()));
// becomes
ipsum.map(|dolor| dolor.sit())?;
```

### `wrap_comments = true`

Breaks comments to fit within the maximum line width (80 characters).

[mit]: LICENSE
[config]: .rustfmt.toml

0 comments on commit 6db1cd1

Please sign in to comment.