Skip to content

Commit 0d6cec9

Browse files
committed
Clippy
1 parent c74d3e7 commit 0d6cec9

File tree

5 files changed

+16
-34
lines changed

5 files changed

+16
-34
lines changed

src/lib.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,7 @@ impl CachePolicy {
250250
res_cc.insert("no-cache".into(), None);
251251
}
252252

253-
Self {
254-
status,
255-
method,
256-
res,
257-
req,
258-
res_cc,
259-
req_cc,
260-
opts,
261-
uri,
262-
response_time,
263-
}
253+
Self { req, res, uri, status, method, opts, res_cc, req_cc, response_time }
264254
}
265255

266256
/// Returns `true` if the response can be stored in a cache. If it's
@@ -431,7 +421,7 @@ impl CachePolicy {
431421
.iter()
432422
.filter(|(h, _)| !HOP_BY_HOP_HEADERS.contains(&h.as_str()))
433423
{
434-
headers.insert(h.to_owned(), v.to_owned());
424+
headers.insert(h.clone(), v.clone());
435425
}
436426

437427
// 9.1. Connection
@@ -587,7 +577,7 @@ impl CachePolicy {
587577
let last_modified = SystemTime::UNIX_EPOCH
588578
+ Duration::from_secs(last_modified.unix_timestamp().max(0) as _);
589579
if let Ok(diff) = server_date.duration_since(last_modified) {
590-
let secs_left = diff.as_secs() as f64 * self.opts.cache_heuristic as f64;
580+
let secs_left = diff.as_secs() as f64 * f64::from(self.opts.cache_heuristic);
591581
return default_min_ttl.max(Duration::from_secs(secs_left as _));
592582
}
593583
}
@@ -738,14 +728,14 @@ impl CachePolicy {
738728
// use other header fields provided in the 304 (Not Modified) response to replace all instances
739729
// of the corresponding header fields in the stored response.
740730
for (header, old_value) in &self.res {
741-
let header = header.to_owned();
731+
let header = header.clone();
742732
if let Some(new_value) = response_headers.get(&header) {
743733
if !EXCLUDED_FROM_REVALIDATION_UPDATE.contains(&header.as_str()) {
744-
new_response_headers.insert(header, new_value.to_owned());
734+
new_response_headers.insert(header, new_value.clone());
745735
continue;
746736
}
747737
}
748-
new_response_headers.insert(header, old_value.to_owned());
738+
new_response_headers.insert(header, old_value.clone());
749739
}
750740
response_status = self.status;
751741
new_response_headers

tests/responsetest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn pre_check_tolerated() {
9898
"cache-control": cc
9999
},
100100
);
101-
assert!(cache.is_stale(now), "{:#?}", cache);
101+
assert!(cache.is_stale(now), "{cache:#?}");
102102
assert!(!cache.is_storable());
103103
assert_eq!(cache.time_to_live(now).as_secs(), 0);
104104
assert_eq!(
@@ -405,7 +405,7 @@ fn blank_cache_control_and_pragma_no_cache() {
405405
"last-modified": date_str(SystemTime::now() - Duration::from_secs(10)),
406406
},
407407
);
408-
assert!(!cache.is_stale(SystemTime::now()), "{:#?}", cache);
408+
assert!(!cache.is_stale(SystemTime::now()), "{cache:#?}");
409409
}
410410

411411
#[test]

tests/revalidate.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ fn very_old_date() -> &'static str {
6262
}
6363

6464
fn assert_no_connection(headers: &HeaderMap<HeaderValue>) {
65-
assert!(!headers.contains_key(header::CONNECTION), "{:#?}", headers);
65+
assert!(!headers.contains_key(header::CONNECTION), "{headers:#?}");
6666
}
6767
fn assert_custom_header(headers: &HeaderMap<HeaderValue>) {
68-
assert!(headers.contains_key("x-custom"), "{:#?}", headers);
68+
assert!(headers.contains_key("x-custom"), "{headers:#?}");
6969
assert_eq!(headers.get("x-custom").unwrap(), "yes");
7070
}
7171

@@ -91,11 +91,7 @@ fn test_ok_if_method_changes_to_head() {
9191
.headers;
9292

9393
assert_custom_header(&headers);
94-
assert!(
95-
headers.contains_key(header::IF_NONE_MATCH),
96-
"{:#?}",
97-
headers
98-
);
94+
assert!(headers.contains_key(header::IF_NONE_MATCH), "{headers:#?}");
9995
assert_eq!(headers.get(header::IF_NONE_MATCH).unwrap(), "\"123456789\"");
10096
}
10197

@@ -505,10 +501,10 @@ fn get_revalidation_request(
505501
match policy.before_request(req, now) {
506502
http_cache_semantics::BeforeRequest::Stale { request, matches } => {
507503
if !matches {
508-
eprintln!("warning: req doesn't match {:#?} vs {:#?}", req, policy);
504+
eprintln!("warning: req doesn't match {req:#?} vs {policy:#?}");
509505
}
510506
request
511507
}
512-
_ => panic!("no revalidation needed {:#?} vs {:#?}", req, policy),
508+
_ => panic!("no revalidation needed {req:#?} vs {policy:#?}"),
513509
}
514510
}

tests/tests.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ fn assert_cached(should_put: bool, response_code: i32) {
7878
assert_eq!(
7979
should_put,
8080
policy.is_storable(),
81-
"{}; {}; {:#?}",
82-
should_put,
83-
response_code,
84-
policy
81+
"{should_put}; {response_code}; {policy:#?}"
8582
);
8683
}
8784

@@ -1122,8 +1119,7 @@ fn test_when_methods_match() {
11221119
now
11231120
)
11241121
.satisfies_without_revalidation(),
1125-
"{:?}",
1126-
policy
1122+
"{policy:?}"
11271123
);
11281124
}
11291125

tests/update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn get_revalidation_request(
134134
match policy.before_request(req, now) {
135135
http_cache_semantics::BeforeRequest::Stale { request, matches } => {
136136
if !matches {
137-
eprintln!("warning: req doesn't match {:#?} vs {:?}", req, policy);
137+
eprintln!("warning: req doesn't match {req:#?} vs {policy:?}");
138138
}
139139
request
140140
}

0 commit comments

Comments
 (0)