Skip to content

Commit 9444ed4

Browse files
authored
Merge pull request #127 from mkantor/clippy-autofix
Apply all of clippy's autofixes.
2 parents c38667f + 2ee2bc0 commit 9444ed4

File tree

11 files changed

+53
-102
lines changed

11 files changed

+53
-102
lines changed

src/content/content_directory.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,15 @@ impl ContentFile {
148148

149149
let file = File::open(&absolute_content_file_path).map_err(|io_error| {
150150
ContentFileError(format!(
151-
"Unable to open file '{}' in '{}' for reading: {}",
152-
relative_path, root, io_error
151+
"Unable to open file '{relative_path}' in '{root}' for reading: {io_error}"
153152
))
154153
})?;
155154

156155
let basename = absolute_content_file_path
157156
.file_name()
158157
.ok_or_else(|| {
159158
ContentFileError(format!(
160-
"Unable to get basename of '{}' in '{}'",
161-
relative_path, root,
159+
"Unable to get basename of '{relative_path}' in '{root}'",
162160
))
163161
})?
164162
.to_str()

src/content/content_engine.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use thiserror::Error;
1717
#[derive(Error, Debug)]
1818
#[error(
1919
"Failed to register handlebars template{}.",
20-
.source.name().map(|known_name| format!(" '{}'", known_name)).unwrap_or_default(),
20+
.source.name().map(|known_name| format!(" '{known_name}'")).unwrap_or_default(),
2121
)]
2222
pub struct TemplateError {
2323
#[from]
@@ -257,8 +257,7 @@ where
257257
let template_name = content.relative_path;
258258
if handlebars_registry.has_template(&template_name) {
259259
return Err(ContentLoadingError::Bug(format!(
260-
"More than one handlebars template has the name '{}'.",
261-
template_name,
260+
"More than one handlebars template has the name '{template_name}'.",
262261
)));
263262
}
264263
handlebars_registry
@@ -313,8 +312,7 @@ where
313312
// (not a directory). If it's the filesystem root then
314313
// it is a directory.
315314
ContentLoadingError::Bug(format!(
316-
"Failed to get a parent directory for the executable at '{}'.",
317-
absolute_path,
315+
"Failed to get a parent directory for the executable at '{absolute_path}'.",
318316
))
319317
})?;
320318

src/content/content_index.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl ContentIndexEntries {
7070
.0
7171
// Non-leaf nodes in the index end with `/` (they
7272
// represent directories).
73-
.entry(format!("{}/", path_component))
73+
.entry(format!("{path_component}/"))
7474
.or_insert_with(|| ContentIndex::Directory(Self::new()));
7575

7676
node = match next_node {
@@ -81,8 +81,7 @@ impl ContentIndexEntries {
8181
return Err(ContentIndexUpdateError {
8282
failed_route: route.clone(),
8383
message: format!(
84-
"There is already a resource at '{}', but that needs to be a directory to accommodate the new route.",
85-
conficting_route,
84+
"There is already a resource at '{conficting_route}', but that needs to be a directory to accommodate the new route.",
8685
)
8786
});
8887
}
@@ -93,7 +92,7 @@ impl ContentIndexEntries {
9392
match node.0.get(basename) {
9493
Some(ContentIndex::Directory(..)) => Err(ContentIndexUpdateError {
9594
failed_route: route.clone(),
96-
message: format!("There is already a directory at '{}'.", route),
95+
message: format!("There is already a directory at '{route}'."),
9796
}),
9897
Some(ContentIndex::Resource(..)) => {
9998
// This route already exists, no need to do anything.

src/content/content_item.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ impl Executable {
249249
serde_json::Value::Object(base_render_data_as_json_map).to_string()
250250
} else {
251251
return Err(RenderingFailedError::Bug(format!(
252-
"Render data did not serialize to a JSON object, instead got `{}`.",
253-
base_render_data_as_json
252+
"Render data did not serialize to a JSON object, instead got `{base_render_data_as_json}`."
254253
)));
255254
}
256255
}
@@ -269,7 +268,7 @@ impl Executable {
269268
)
270269
.spawn()
271270
.map_err(|io_error| RenderingFailedError::ExecutableError {
272-
message: format!("Unable to execute program: {}", io_error),
271+
message: format!("Unable to execute program: {io_error}"),
273272
program: self.program.clone(),
274273
working_directory: self.working_directory.clone(),
275274
})?;

src/content/content_registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Render for ContentRepresentations {
9494
}
9595
}
9696
Err(error) => {
97-
log::warn!("Rendering failure: {}", error);
97+
log::warn!("Rendering failure: {error}");
9898
errors.push(error)
9999
}
100100
};

src/content/handlebars_helpers/get.rs

Lines changed: 25 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,13 @@ where
6262
.ok_or_else(|| {
6363
handlebars::RenderErrorReason::Other(format!(
6464
"The `get` helper's first argument must be a string (the route of the content \
65-
item to get), but it was `{}`.",
66-
param_0,
65+
item to get), but it was `{param_0}`.",
6766
))
6867
})?
6968
.parse::<Route>()
7069
.map_err(|error| {
7170
handlebars::RenderErrorReason::Other(format!(
72-
"The `get` helper's first argument (`{}`) must be a valid route: {}",
73-
param_0, error,
71+
"The `get` helper's first argument (`{param_0}`) must be a valid route: {error}",
7472
))
7573
})?;
7674

@@ -81,8 +79,7 @@ where
8179
let param_1_as_object = match param_1.map(|value| {
8280
value.as_object().ok_or_else(|| {
8381
handlebars::RenderErrorReason::Other(format!(
84-
"Custom context provided to `get \"{}\"` must be an object, but it was `{}`.",
85-
route, value,
82+
"Custom context provided to `get \"{route}\"` must be an object, but it was `{value}`.",
8683
))
8784
})
8885
}) {
@@ -109,10 +106,7 @@ where
109106
});
110107

111108
let content_item = content_engine.get_internal(&route).ok_or_else(|| {
112-
handlebars::RenderErrorReason::Other(format!(
113-
"No content found for `get \"{}\"`.",
114-
route
115-
))
109+
handlebars::RenderErrorReason::Other(format!("No content found for `get \"{route}\"`."))
116110
})?;
117111

118112
let current_render_data = handlebars_context.data().as_object().ok_or_else(|| {
@@ -131,10 +125,8 @@ where
131125
serde_json::Value::Object(modified_context_data_as_json_map) => modified_context_data_as_json_map,
132126
_ => {
133127
return Err(handlebars::RenderError::from(handlebars::RenderErrorReason::Other(format!(
134-
"The `get \"{}\"` helper call failed because the pre-existing handlebars render context \
135-
was not an object (it was `{}`).",
136-
route,
137-
modified_context_data_as_json
128+
"The `get \"{route}\"` helper call failed because the pre-existing handlebars render context \
129+
was not an object (it was `{modified_context_data_as_json}`)."
138130
))))
139131
}
140132
}
@@ -166,8 +158,7 @@ where
166158
.render(context, &[target_media_type.into_media_range()])
167159
.map_err(|render_error| {
168160
handlebars::RenderErrorReason::Other(format!(
169-
"The `get \"{}\"` helper call failed because {} could not be rendered: {}",
170-
route, route, render_error,
161+
"The `get \"{route}\"` helper call failed because {route} could not be rendered: {render_error}",
171162
))
172163
})?;
173164

@@ -183,11 +174,8 @@ where
183174
))
184175
.map_err(|streaming_error| {
185176
handlebars::RenderErrorReason::Other(format!(
186-
"The `get \"{}\"` helper call failed because there was an error collecting the rendered content \
187-
for {}: {}",
188-
route,
189-
route,
190-
streaming_error,
177+
"The `get \"{route}\"` helper call failed because there was an error collecting the rendered content \
178+
for {route}: {streaming_error}",
191179
))
192180
})?;
193181
let rendered_content_as_string = String::from_utf8(bytes)?;
@@ -207,11 +195,9 @@ fn get_target_media_type(
207195
.and_then(|media_type_essence| media_type_essence.parse::<MediaType>().ok())
208196
.ok_or_else(|| {
209197
handlebars::RenderErrorReason::Other(format!(
210-
"The `get \"{}\"` helper call failed because a valid target media type could not be found \
211-
in the handlebars context. The context JSON must contain a property at `{}` whose value is \
198+
"The `get \"{route}\"` helper call failed because a valid target media type could not be found \
199+
in the handlebars context. The context JSON must contain a property at `{TARGET_MEDIA_TYPE_PROPERTY_NAME}` whose value is \
212200
a valid media type essence string.",
213-
route,
214-
TARGET_MEDIA_TYPE_PROPERTY_NAME,
215201
))
216202
})?;
217203
Ok(target_media_type)
@@ -227,11 +213,9 @@ fn get_optional_request_route(
227213
.and_then(|request_data| request_data.get(ROUTE_PROPERTY_NAME))
228214
.ok_or_else(|| {
229215
handlebars::RenderErrorReason::Other(format!(
230-
"The `get \"{}\"` helper call failed because the request route could not be found in the \
231-
handlebars context. The context JSON must contain a property at `{}.{}` whose value is a \
232-
string or null.",
233-
route,
234-
REQUEST_DATA_PROPERTY_NAME, ROUTE_PROPERTY_NAME
216+
"The `get \"{route}\"` helper call failed because the request route could not be found in the \
217+
handlebars context. The context JSON must contain a property at `{REQUEST_DATA_PROPERTY_NAME}.{ROUTE_PROPERTY_NAME}` whose value is a \
218+
string or null."
235219
))
236220
})?;
237221

@@ -241,19 +225,15 @@ fn get_optional_request_route(
241225
let request_route = request_route_value.as_str()
242226
.ok_or_else(|| {
243227
handlebars::RenderErrorReason::Other(format!(
244-
"The `get \"{}\"` helper call failed because the request route in the handlebars context was \
245-
not a string or null (it was `{}`).",
246-
route,
247-
request_route_value,
228+
"The `get \"{route}\"` helper call failed because the request route in the handlebars context was \
229+
not a string or null (it was `{request_route_value}`).",
248230
))
249231
})?
250232
.parse::<Route>()
251233
.map_err(|error| {
252234
handlebars::RenderErrorReason::Other(format!(
253-
"The `get \"{}\"` helper call failed because the request route in the handlebars context was \
254-
invalid ({}).",
255-
route,
256-
error,
235+
"The `get \"{route}\"` helper call failed because the request route in the handlebars context was \
236+
invalid ({error}).",
257237
))
258238
})?;
259239
Some(request_route)
@@ -271,19 +251,15 @@ fn get_query_parameters(
271251
.and_then(|request_data| request_data.get(QUERY_PARAMETERS_PROPERTY_NAME))
272252
.ok_or_else(|| {
273253
handlebars::RenderErrorReason::Other(format!(
274-
"The `get \"{}\"` helper call failed because the query parameters could not be found in the \
275-
handlebars context. The context JSON must contain a property at `{}.{}` whose value is a map.",
276-
route,
277-
REQUEST_DATA_PROPERTY_NAME,
278-
QUERY_PARAMETERS_PROPERTY_NAME,
254+
"The `get \"{route}\"` helper call failed because the query parameters could not be found in the \
255+
handlebars context. The context JSON must contain a property at `{REQUEST_DATA_PROPERTY_NAME}.{QUERY_PARAMETERS_PROPERTY_NAME}` whose value is a map.",
279256
))
280257
})?
281258
.as_object()
282259
.ok_or_else(|| {
283260
handlebars::RenderErrorReason::Other(format!(
284-
"The `get \"{}\"` helper call failed because the query parameters in the handlebars context \
261+
"The `get \"{route}\"` helper call failed because the query parameters in the handlebars context \
285262
was not a map.",
286-
route,
287263
))
288264
})?
289265
.into_iter()
@@ -305,18 +281,14 @@ fn get_request_headers(
305281
.and_then(|request_data| request_data.get(REQUEST_HEADERS_PROPERTY_NAME))
306282
.ok_or_else(|| {
307283
handlebars::RenderErrorReason::Other(format!(
308-
"The `get \"{}\"` helper call failed because the request headers could not be found in \
309-
the handlebars context. The context JSON must contain a property at `{}.{}` whose value \
310-
is a map.",
311-
route,
312-
REQUEST_DATA_PROPERTY_NAME,
313-
REQUEST_HEADERS_PROPERTY_NAME
284+
"The `get \"{route}\"` helper call failed because the request headers could not be found in \
285+
the handlebars context. The context JSON must contain a property at `{REQUEST_DATA_PROPERTY_NAME}.{REQUEST_HEADERS_PROPERTY_NAME}` whose value \
286+
is a map."
314287
))
315288
})?.as_object().ok_or_else(|| {
316289
handlebars::RenderErrorReason::Other(format!(
317-
"The `get \"{}\"` helper call failed because the request headers in the handlebars context \
290+
"The `get \"{route}\"` helper call failed because the request headers in the handlebars context \
318291
was not a map.",
319-
route,
320292
))
321293
})?
322294
.into_iter()

src/content/mime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl FromStr for MediaType {
4444
type Err = MediaTypeFromStrError;
4545
fn from_str(input: &str) -> Result<Self, Self::Err> {
4646
let mime = Mime::from_str(input)
47-
.map_err(|error| MediaTypeFromStrError(format!("Malformed media type: {}", error)))?;
47+
.map_err(|error| MediaTypeFromStrError(format!("Malformed media type: {error}")))?;
4848
MediaType::from_media_range(mime).ok_or_else(|| {
4949
MediaTypeFromStrError(String::from(
5050
"Input is a valid media range, but not a specific media type",

src/content/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ pub enum StreamError {
7272
#[error(
7373
"Process exited with {}{}",
7474
match .exit_code {
75-
Some(code) => format!("code {}", code),
75+
Some(code) => format!("code {code}"),
7676
None => String::from("unknown code"),
7777
},
78-
.stderr_contents.as_ref().map(|message| format!(": {}", message)).unwrap_or_default(),
78+
.stderr_contents.as_ref().map(|message| format!(": {message}")).unwrap_or_default(),
7979
)]
8080
ExecutableExitedWithNonzero {
8181
pid: u32,

src/content/route.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn canonicalize_route(route: &str) -> Result<String, InvalidRouteError> {
2121

2222
let canonicalized_route = canonicalized_components.collect::<Vec<&str>>().join("/");
2323

24-
Ok(format!("/{}", canonicalized_route))
24+
Ok(format!("/{canonicalized_route}"))
2525
}
2626
}
2727

0 commit comments

Comments
 (0)