Skip to content

Commit

Permalink
Fix clippy warnings (#473)
Browse files Browse the repository at this point in the history
* Fix clippy warnings

* Fix clippy 1.77 warnings
  • Loading branch information
Asthowen committed May 9, 2024
1 parent d53405b commit 6185835
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Headless Chrome

[![Build Status](https://github.com/atroche/rust-headless-chrome/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/atroche/rust-headless-chrome/actions/workflows/ci.yml)
[![Build Status](https://github.com/rust-headless-chrome/rust-headless-chrome/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/atroche/rust-headless-chrome/actions/workflows/ci.yml)
[![Crate](https://img.shields.io/crates/v/headless_chrome.svg)](https://crates.io/crates/headless_chrome)
[![API](https://docs.rs/headless_chrome/badge.svg)](https://docs.rs/headless_chrome)
[![Discord channel](https://img.shields.io/discord/557374784233799681.svg?logo=discord)](https://discord.gg/yyGEzcc)
Expand Down
6 changes: 5 additions & 1 deletion src/browser/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ impl Fetcher {
println!("{path:?}");

info!("Creating file for download: {}", &path.display());
let mut file = OpenOptions::new().create(true).write(true).open(&path)?;
let mut file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&path)?;

let resp = ureq::get(&url).call();
io::copy(&mut resp?.into_reader(), &mut file)?;
Expand Down
2 changes: 1 addition & 1 deletion src/browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl Browser {
#[deprecated(since = "1.0.4", note = "Use new_tab() instead.")]
pub fn wait_for_initial_tab(&self) -> Result<Arc<Tab>> {
match util::Wait::with_timeout(Duration::from_secs(10))
.until(|| self.inner.tabs.lock().unwrap().first().map(Arc::clone))
.until(|| self.inner.tabs.lock().unwrap().first().cloned())
{
Ok(tab) => Ok(tab),
Err(_) => self.new_tab(),
Expand Down
2 changes: 1 addition & 1 deletion src/browser/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct ForTesting;
#[cfg(test)]
impl ForTesting {
thread_local! {
static USER_DATA_DIR: RefCell<Option<String>> = RefCell::new(None);
static USER_DATA_DIR: RefCell<Option<String>> = const { RefCell::new(None) };
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/browser/tab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,14 +702,14 @@ impl Tab {
query: query.to_string(),
include_user_agent_shadow_dom: None,
})
.and_then(|o| {
.map(|o| {
match self.call_method(DOM::GetSearchResults {
search_id: o.search_id,
from_index: 0,
to_index: o.result_count,
}) {
Ok(res) => Ok(res.node_ids.get(0).cloned().unwrap_or(0)),
Err(_) => Ok(0),
Ok(res) => res.node_ids.first().copied().unwrap_or(0),
Err(_) => 0,
}
})
.and_then(|id| {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ clippy::wildcard_imports, // for autogen protocol.rs
clippy::cast_possible_truncation, // for types.rs:189 & 190
clippy::cast_sign_loss, // for tab/element/mod.rs:492 & 493
clippy::cast_lossless, // for tab/element/mod.rs:492 & 493
clippy::vtable_address_comparisons, // for tab/mod.rs:1415
ambiguous_wide_pointer_comparisons, // for tab/mod.rs:1415
clippy::derivable_impls, // for types.rs Default for PrintToPDF because autogen
clippy::type_complexity, // for transport/web_socket_connection.rs:133
clippy::manual_let_else, // for transport/web_socket_connection.rs:142
Expand Down
9 changes: 5 additions & 4 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ impl Default for Wait {
}

pub fn extract_midpoint(remote_obj: RemoteObject) -> Result<Point> {
let mut prop_map = HashMap::new();

match remote_obj.preview.map(|v| {
let point = remote_obj.preview.map(|v| {
let mut prop_map = HashMap::new();
for prop in v.properties {
prop_map.insert(prop.name, prop.value.unwrap().parse::<f64>().unwrap());
}
Point {
x: prop_map["x"] + (prop_map["width"] / 2.0),
y: prop_map["y"] + (prop_map["height"] / 2.0),
}
}) {
});

match point {
Some(v) => Ok(v),
None => Ok(Point { x: 0.0, y: 0.0 }),
}
Expand Down

0 comments on commit 6185835

Please sign in to comment.