Skip to content

Commit 913f9a4

Browse files
authored
Simplify rustfmt config and switch to stable rustfmt (#242)
1 parent d5ad1f1 commit 913f9a4

27 files changed

+295
-553
lines changed

.github/workflows/rust.yml

+3-13
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@ jobs:
1414
runs-on: ubuntu-18.04
1515
steps:
1616
- uses: actions/checkout@230611dbd0eb52da1e1f4f7bc8bb0c3a339fc8b7
17-
- uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746
18-
with:
19-
toolchain: nightly-2021-03-25
20-
default: false
21-
components: rustfmt
2217
- name: Report cargo version
23-
run: cargo +nightly-2021-03-25 --version
18+
run: cargo --version
2419
- name: Report rustfmt version
25-
run: cargo +nightly-2021-03-25 fmt -- --version
20+
run: cargo fmt -- --version
2621
- name: Check style
27-
run: cargo +nightly-2021-03-25 fmt -- --check
22+
run: cargo fmt -- --check
2823

2924
clippy-lint:
3025
runs-on: ubuntu-18.04
@@ -44,11 +39,6 @@ jobs:
4439
os: [ubuntu-18.04, windows-2019, macos-10.15]
4540
steps:
4641
- uses: actions/checkout@230611dbd0eb52da1e1f4f7bc8bb0c3a339fc8b7
47-
# Temporary fork until https://github.com/actions-rs/toolchain/pull/209 is merged
48-
- uses: oxidecomputer/actions-rs_toolchain@ad3f86084a8a5acf2c09cb691421b31cf8af7a36
49-
with:
50-
profile: minimal
51-
override: true
5242
- name: Report cargo version
5343
run: cargo --version
5444
- name: Report rustc version

.vscode/settings.json

-8
This file was deleted.

README.adoc

+2-20
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,16 @@ You can build the documentation yourself with:
1515
$ cargo +nightly doc
1616
----
1717

18-
1918
== Contributing
2019

21-
For maintainers (e.g., publishing new releases and managing dependabot), see link:./MAINTAINERS.adoc[MAINTAINERS.adoc].
22-
23-
=== Building and testing
24-
2520
You can **build and run the whole test suite** with `cargo test`. The test
2621
suite runs cleanly and should remain clean.
2722

28-
=== Code formatting and lint
29-
30-
Dropshot works with stable Rust versions, but for consistency the code is
31-
_formatted_ with a specific version of `rustfmt`. To contribute to Dropshot,
32-
you will need to have installed the `nightly-2021-03-25` version of the Rust
33-
toolchain:
34-
35-
----
36-
$ rustup install nightly-2021-03-25
37-
----
38-
39-
You can then **format the code** using `cargo +nightly-2021-03-25 fmt` or
40-
`rustfmt +nightly-2021-03-25`. Make sure to run this before pushing changes.
41-
The CI uses this version of `rustfmt` to check that the code is correctly
42-
formatted.
23+
You can format the code using `cargo fmt`. CI checks that code is correctly formatted.
4324

4425
https://github.com/rust-lang/rust-clippy[Clippy] is used to check for common code issues. (We disable the style checks.) You can run it with `cargo clippy`. CI will run clippy as well.
4526

27+
For maintainers (e.g., publishing new releases and managing dependabot), see link:./MAINTAINERS.adoc[MAINTAINERS.adoc].
4628

4729
== Configuration reference
4830

dropshot/examples/basic.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ async fn main() -> Result<(), String> {
3535
* For simplicity, we'll configure an "info"-level logger that writes to
3636
* stderr assuming that it's a terminal.
3737
*/
38-
let config_logging = ConfigLogging::StderrTerminal {
39-
level: ConfigLoggingLevel::Info,
40-
};
38+
let config_logging =
39+
ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Info };
4140
let log = config_logging
4241
.to_logger("example-basic")
4342
.map_err(|error| format!("failed to create logger: {}", error))?;
@@ -82,9 +81,7 @@ impl ExampleContext {
8281
* Return a new ExampleContext.
8382
*/
8483
pub fn new() -> ExampleContext {
85-
ExampleContext {
86-
counter: AtomicU64::new(0),
87-
}
84+
ExampleContext { counter: AtomicU64::new(0) }
8885
}
8986
}
9087

dropshot/examples/file_server.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ async fn main() -> Result<(), String> {
3535
* For simplicity, we'll configure an "info"-level logger that writes to
3636
* stderr assuming that it's a terminal.
3737
*/
38-
let config_logging = ConfigLogging::StderrTerminal {
39-
level: ConfigLoggingLevel::Info,
40-
};
38+
let config_logging =
39+
ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Info };
4140
let log = config_logging
4241
.to_logger("example-basic")
4342
.map_err(|error| format!("failed to create logger: {}", error))?;
@@ -51,9 +50,7 @@ async fn main() -> Result<(), String> {
5150
/*
5251
* Specify the directory we want to serve.
5352
*/
54-
let context = FileServerContext {
55-
base: PathBuf::from("."),
56-
};
53+
let context = FileServerContext { base: PathBuf::from(".") };
5754

5855
/*
5956
* Set up the server.

dropshot/examples/https.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ async fn main() -> Result<(), String> {
8383
* For simplicity, we'll configure an "info"-level logger that writes to
8484
* stderr assuming that it's a terminal.
8585
*/
86-
let config_logging = ConfigLogging::StderrTerminal {
87-
level: ConfigLoggingLevel::Info,
88-
};
86+
let config_logging =
87+
ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Info };
8988
let log = config_logging
9089
.to_logger("example-basic")
9190
.map_err(|error| format!("failed to create logger: {}", error))?;
@@ -130,9 +129,7 @@ impl ExampleContext {
130129
* Return a new ExampleContext.
131130
*/
132131
pub fn new() -> ExampleContext {
133-
ExampleContext {
134-
counter: AtomicU64::new(0),
135-
}
132+
ExampleContext { counter: AtomicU64::new(0) }
136133
}
137134
}
138135

dropshot/examples/index.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ async fn main() -> Result<(), String> {
3131
* For simplicity, we'll configure an "info"-level logger that writes to
3232
* stderr assuming that it's a terminal.
3333
*/
34-
let config_logging = ConfigLogging::StderrTerminal {
35-
level: ConfigLoggingLevel::Info,
36-
};
34+
let config_logging =
35+
ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Info };
3736
let log = config_logging
3837
.to_logger("example-basic")
3938
.map_err(|error| format!("failed to create logger: {}", error))?;

dropshot/examples/module-basic.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ async fn main() -> Result<(), String> {
2626
* For simplicity, we'll configure an "info"-level logger that writes to
2727
* stderr assuming that it's a terminal.
2828
*/
29-
let config_logging = ConfigLogging::StderrTerminal {
30-
level: ConfigLoggingLevel::Info,
31-
};
29+
let config_logging =
30+
ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Info };
3231
let log = config_logging
3332
.to_logger("example-basic")
3433
.map_err(|error| format!("failed to create logger: {}", error))?;
@@ -73,9 +72,7 @@ impl ExampleContext {
7372
* Return a new ExampleContext.
7473
*/
7574
pub fn new() -> ExampleContext {
76-
ExampleContext {
77-
counter: AtomicU64::new(0),
78-
}
75+
ExampleContext { counter: AtomicU64::new(0) }
7976
}
8077
}
8178

dropshot/examples/module-shared-context.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ async fn main() -> Result<(), String> {
3434
* For simplicity, we'll configure an "info"-level logger that writes to
3535
* stderr assuming that it's a terminal.
3636
*/
37-
let config_logging = ConfigLogging::StderrTerminal {
38-
level: ConfigLoggingLevel::Info,
39-
};
37+
let config_logging =
38+
ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Info };
4039
let log = config_logging
4140
.to_logger("example-basic")
4241
.map_err(|error| format!("failed to create logger: {}", error))?;
@@ -102,9 +101,7 @@ impl ExampleContext {
102101
* Return a new ExampleContext.
103102
*/
104103
pub fn new() -> ExampleContext {
105-
ExampleContext {
106-
counter: AtomicU64::new(0),
107-
}
104+
ExampleContext { counter: AtomicU64::new(0) }
108105
}
109106
}
110107

dropshot/examples/pagination-basic.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ async fn example_list_projects(
9191
.map(|(_, project)| project.clone())
9292
.collect()
9393
}
94-
WhichPage::Next(ProjectPage {
95-
name: last_seen,
96-
}) => {
94+
WhichPage::Next(ProjectPage { name: last_seen }) => {
9795
/* Return a list of the first "limit" projects after this name. */
9896
tree.range((Bound::Excluded(last_seen.clone()), Bound::Unbounded))
9997
.take(limit)
@@ -105,9 +103,7 @@ async fn example_list_projects(
105103
Ok(HttpResponseOk(ResultsPage::new(
106104
projects,
107105
&EmptyScanParams {},
108-
|p: &Project, _| ProjectPage {
109-
name: p.name.clone(),
110-
},
106+
|p: &Project, _| ProjectPage { name: p.name.clone() },
111107
)?))
112108
}
113109

@@ -126,9 +122,7 @@ async fn main() -> Result<(), String> {
126122
let mut tree = BTreeMap::new();
127123
for n in 1..1000 {
128124
let name = format!("project{:03}", n);
129-
let project = Project {
130-
name: name.clone(),
131-
};
125+
let project = Project { name: name.clone() };
132126
tree.insert(name, project);
133127
}
134128

@@ -140,9 +134,8 @@ async fn main() -> Result<(), String> {
140134
bind_address: SocketAddr::from((Ipv4Addr::LOCALHOST, port)),
141135
..Default::default()
142136
};
143-
let config_logging = ConfigLogging::StderrTerminal {
144-
level: ConfigLoggingLevel::Debug,
145-
};
137+
let config_logging =
138+
ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Debug };
146139
let log = config_logging
147140
.to_logger("example-pagination-basic")
148141
.map_err(|error| format!("failed to create logger: {}", error))?;

dropshot/examples/pagination-multiple-resources.rs

+21-30
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,25 @@ fn page_selector<T: HasIdentity>(
119119
scan_params: &ExScanParams,
120120
) -> ExPageSelector {
121121
match scan_params {
122-
ExScanParams {
123-
sort: ExSortMode::ByIdAscending,
124-
} => ExPageSelector::Id(Ascending, *item.id()),
125-
ExScanParams {
126-
sort: ExSortMode::ByIdDescending,
127-
} => ExPageSelector::Id(Descending, *item.id()),
128-
ExScanParams {
129-
sort: ExSortMode::ByNameAscending,
130-
} => ExPageSelector::Name(Ascending, item.name().to_string()),
131-
ExScanParams {
132-
sort: ExSortMode::ByNameDescending,
133-
} => ExPageSelector::Name(Descending, item.name().to_string()),
122+
ExScanParams { sort: ExSortMode::ByIdAscending } => {
123+
ExPageSelector::Id(Ascending, *item.id())
124+
}
125+
ExScanParams { sort: ExSortMode::ByIdDescending } => {
126+
ExPageSelector::Id(Descending, *item.id())
127+
}
128+
ExScanParams { sort: ExSortMode::ByNameAscending } => {
129+
ExPageSelector::Name(Ascending, item.name().to_string())
130+
}
131+
ExScanParams { sort: ExSortMode::ByNameDescending } => {
132+
ExPageSelector::Name(Descending, item.name().to_string())
133+
}
134134
}
135135
}
136136

137137
fn scan_params(p: &WhichPage<ExScanParams, ExPageSelector>) -> ExScanParams {
138138
ExScanParams {
139139
sort: match p {
140-
WhichPage::First(ExScanParams {
141-
sort,
142-
}) => sort.clone(),
140+
WhichPage::First(ExScanParams { sort }) => sort.clone(),
143141

144142
WhichPage::Next(ExPageSelector::Id(Ascending, ..)) => {
145143
ExSortMode::ByIdAscending
@@ -297,9 +295,8 @@ async fn main() -> Result<(), String> {
297295
bind_address: SocketAddr::from((Ipv4Addr::LOCALHOST, port)),
298296
..Default::default()
299297
};
300-
let config_logging = ConfigLogging::StderrTerminal {
301-
level: ConfigLoggingLevel::Debug,
302-
};
298+
let config_logging =
299+
ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Debug };
303300
let log = config_logging
304301
.to_logger("example-pagination-basic")
305302
.map_err(|error| format!("failed to create logger: {}", error))?;
@@ -346,26 +343,20 @@ impl DataCollection {
346343
};
347344
for n in 1..1000 {
348345
let pname = format!("project{:03}", n);
349-
let project = Arc::new(Project {
350-
id: Uuid::new_v4(),
351-
name: pname.clone(),
352-
});
346+
let project =
347+
Arc::new(Project { id: Uuid::new_v4(), name: pname.clone() });
353348
data.projects_by_name.insert(pname.clone(), Arc::clone(&project));
354349
data.projects_by_id.insert(project.id, project);
355350

356351
let dname = format!("disk{:03}", n);
357-
let disk = Arc::new(Disk {
358-
id: Uuid::new_v4(),
359-
name: dname.clone(),
360-
});
352+
let disk =
353+
Arc::new(Disk { id: Uuid::new_v4(), name: dname.clone() });
361354
data.disks_by_name.insert(dname.clone(), Arc::clone(&disk));
362355
data.disks_by_id.insert(disk.id, disk);
363356

364357
let iname = format!("disk{:03}", n);
365-
let instance = Arc::new(Instance {
366-
id: Uuid::new_v4(),
367-
name: iname.clone(),
368-
});
358+
let instance =
359+
Arc::new(Instance { id: Uuid::new_v4(), name: iname.clone() });
369360
data.instances_by_name.insert(iname.clone(), Arc::clone(&instance));
370361
data.instances_by_id.insert(instance.id, instance);
371362
}

dropshot/examples/pagination-multiple-sorts.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,7 @@ async fn example_list_projects(
241241
let data = rqctx.context();
242242
let scan_params = ProjectScanParams {
243243
sort: match &pag_params.page {
244-
WhichPage::First(ProjectScanParams {
245-
sort,
246-
}) => sort.clone(),
244+
WhichPage::First(ProjectScanParams { sort }) => sort.clone(),
247245

248246
WhichPage::Next(ProjectScanPageSelector::Name(Ascending, ..)) => {
249247
ProjectSort::ByNameAscending
@@ -313,9 +311,8 @@ async fn main() -> Result<(), String> {
313311
bind_address: SocketAddr::from((Ipv4Addr::LOCALHOST, port)),
314312
..Default::default()
315313
};
316-
let config_logging = ConfigLogging::StderrTerminal {
317-
level: ConfigLoggingLevel::Debug,
318-
};
314+
let config_logging =
315+
ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Debug };
319316
let log = config_logging
320317
.to_logger("example-pagination-basic")
321318
.map_err(|error| format!("failed to create logger: {}", error))?;
@@ -341,9 +338,7 @@ fn print_example_requests(log: slog::Logger, addr: &SocketAddr) {
341338
ProjectSort::ByMtimeDescending,
342339
];
343340
for mode in all_modes {
344-
let to_print = ProjectScanParams {
345-
sort: mode,
346-
};
341+
let to_print = ProjectScanParams { sort: mode };
347342
let query_string = serde_urlencoded::to_string(to_print).unwrap();
348343
let uri = Uri::builder()
349344
.scheme("http")

dropshot/examples/petstore.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ async fn find_pets_by_tags(
156156
tags: None,
157157
status: None,
158158
};
159-
tmp = FindByTagsScanParams {
160-
tags: page_selector.tags.clone(),
161-
};
159+
tmp = FindByTagsScanParams { tags: page_selector.tags.clone() };
162160
(vec![pet], &tmp)
163161
}
164162
};

0 commit comments

Comments
 (0)