Skip to content

Commit e684f64

Browse files
committed
refactor: replace bare .unwrap() with documented .expect() in hot paths
1 parent 52e3347 commit e684f64

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ pub fn build_client() -> WreqClient {
7373
let emulation_os = [EmulationOS::Android, EmulationOS::Windows, EmulationOS::Linux];
7474

7575
let emulation = EmulationOption::builder()
76-
.emulation(*fastrand::choice(emulations.iter()).unwrap())
77-
.emulation_os(*fastrand::choice(emulation_os.iter()).unwrap())
76+
.emulation(*fastrand::choice(emulations.iter()).expect("emulations is a non-empty array literal"))
77+
.emulation_os(*fastrand::choice(emulation_os.iter()).expect("emulation_os is a non-empty array literal"))
7878
.build()
7979
.emulation();
8080

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ async fn main() {
185185
}
186186
}
187187

188-
let address = matches.get_one::<String>("address").unwrap();
189-
let port = matches.get_one::<String>("port").unwrap();
188+
let address = matches.get_one::<String>("address").expect("'address' has a default_value and is always present");
189+
let port = matches.get_one::<String>("port").expect("'port' has a default_value and is always present");
190190
let hsts = matches.get_one("hsts").map(|m: &String| m.as_str());
191191

192192
let ipv4_only = std::env::var("IPV4_ONLY").is_ok() || matches.get_flag("ipv4-only");

src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,8 @@ async fn compress_response(req_headers: &HeaderMap<header::HeaderValue>, res: &m
604604
let body_bytes: Vec<u8> = {
605605
// Swap body with empty, collect old body
606606
let old_body = std::mem::replace(res.body_mut(), empty());
607-
// Body error type is Infallible, so unwrap is safe
608-
old_body.collect().await.unwrap().to_bytes().to_vec()
607+
// Body error type is Infallible, so collect cannot fail
608+
old_body.collect().await.expect("Body<Infallible> collect cannot fail").to_bytes().to_vec()
609609
};
610610

611611
// Don't bother compressing tiny responses

0 commit comments

Comments
 (0)